-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: add latest bore and allow ts declaration generation #157
Changes from all commits
093acc8
00fed68
e8eed95
1742ef4
d24b2bd
ee94162
4fa8a55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const ColorTypes = { | ||
export const ColorTypes = { | ||
brand: 'brand', | ||
info: 'info', | ||
warning: 'warning', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type ClickEvent = typeof HTMLElement.prototype.onclick; | ||
export type FocusEvent = typeof HTMLElement.prototype.onfocus; | ||
export type BlurEvent = typeof HTMLElement.prototype.onblur; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @TODO this should maybe be a part of Skate | ||
export type IntrinsicCustomElement<P> = P & Partial<HTMLElement>; | ||
// @TODO this should maybe be a part of Bore | ||
export type IntrinsicBoreElement<A, E> = { attrs?: A } & { events?: E }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const Sizes = { | ||
export const Sizes = { | ||
xsmall: 'xsmall', | ||
small: 'small', | ||
medium: 'medium', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,64 @@ | ||
import * as expect from 'expect'; | ||
import { h } from '../_helpers'; | ||
import { mount } from 'bore'; | ||
import { h, mount } from 'bore'; | ||
import { emit } from 'skatejs'; | ||
|
||
import { Button } from './index'; | ||
|
||
describe( Button.is, () => { | ||
|
||
describe( `Custom element`, () => { | ||
it( `should be registered`, () => { | ||
expect( customElements.get( Button.is ) ).toBe( Button ); | ||
}); | ||
it( `should render via JSX IntrinsicElement`, () => { | ||
return mount( <bl-button>Hello</bl-button> ).wait( (element) => { | ||
expect( element.node.localName ).toBe( Button.is ); | ||
describe( `Custom element`, () => { | ||
|
||
it( `should be registered`, () => { | ||
expect( customElements.get( Button.is ) ).toBe( Button ); | ||
}); | ||
}); | ||
it( `should render`, () => { | ||
return mount( <Button /> ).wait(( element ) => { | ||
expect( element.has( '.c-button' ) ).toBe( true ); | ||
|
||
it( `should render via JSX IntrinsicElement`, () => { | ||
return mount( <bl-button>Hello</bl-button> ).wait(( element ) => { | ||
expect( element.node.localName ).toBe( Button.is ); | ||
}); | ||
}); | ||
|
||
it( `should render`, () => { | ||
return mount( <Button /> ).wait(( element ) => { | ||
expect( element.has( '.c-button' ) ).toBe( true ); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe( `API`, () => { | ||
describe( `API`, () => { | ||
|
||
describe( `[color]`, () => { | ||
describe( `[color]`, () => { | ||
|
||
it( `should render no color class on button by default`, () => { | ||
return mount(<bl-button attributes={{color: 'brand'} as any}>huhuh</bl-button>).wait(( element ) => { | ||
expect( element.one( 'button' ).node.className ).toContain( 'c-button' ); | ||
it( `should render no color class on button by default`, () => { | ||
return mount( <bl-button attrs={{ color: 'brand' }}>huhuh</bl-button> ).wait(( element ) => { | ||
expect( element.one( 'button' ).node.className ).toContain( 'c-button' ); | ||
}); | ||
}); | ||
|
||
it( `should render color class on button`, () => { | ||
return mount( <bl-button attrs={{ color: 'info' }}>hello</bl-button> ).wait(( element ) => { | ||
expect( element.has( '.c-button--info' ) ).toBe( true ); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
it( `should render color class on button`, () => { | ||
return mount( <bl-button attributes={ { color: 'info' } as any }>hello</bl-button> ).wait(( element ) => { | ||
expect( element.has( '.c-button--info' ) ).toBe( true ); | ||
describe( `events`, () => { | ||
|
||
it( `should handle click`, () => { | ||
|
||
let clickTriggered = false; | ||
const handleClick = ( e: MouseEvent ) => { clickTriggered = true; }; | ||
|
||
return mount( <bl-button events={{ click: handleClick }}>Click me</bl-button> ) | ||
.wait(( element ) => { | ||
emit( element.node, 'click' ); | ||
expect( clickTriggered ).toBe( true ); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
import { h, Component, prop } from 'skatejs'; | ||
import { h, Component, prop, ComponentProps } from 'skatejs'; | ||
|
||
import { ColorType, cssClassForColorType, css } from '../_helpers'; | ||
import { | ||
ColorType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking - what about change order of imports to first helpers, then types? like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm thats too much nit picking IMHO. But I see your point. We are importing a lot of stuff from Important is to always order
Maybe we can extract this definitions to root Also that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe next time 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cheers mate 🍺 |
||
cssClassForColorType, | ||
css, | ||
GenericTypes, | ||
GenericEvents | ||
} from '../_helpers'; | ||
|
||
import styles from './Button.scss'; | ||
|
||
// public | ||
type ButtonProps = Props & EventProps; | ||
type Props = { | ||
export type ButtonProps = Props & EventHandlers; | ||
|
||
export type Props = { | ||
disabled?: boolean, | ||
block?: boolean, | ||
close?: boolean, | ||
ghost?: boolean, | ||
color?: ColorType, | ||
}; | ||
type EventProps = { | ||
onClick?: typeof HTMLElement.prototype.onclick, | ||
|
||
export type Events = { | ||
click?: GenericEvents.ClickEvent, | ||
}; | ||
export type EventHandlers = { | ||
onClick?: GenericEvents.ClickEvent, | ||
}; | ||
|
||
declare global { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'bl-button': ButtonProps & Partial<HTMLElement>, | ||
'bl-button': GenericTypes.IntrinsicCustomElement<ButtonProps> & GenericTypes.IntrinsicBoreElement<Props, Events> | ||
} | ||
} | ||
} | ||
|
||
export class Button extends Component<ButtonProps> { | ||
static get is() { return 'bl-button'; } | ||
static get props() { | ||
static get props(): ComponentProps<Button, Props> { | ||
return { | ||
disabled: prop.boolean( { | ||
attribute: true | ||
|
@@ -47,7 +57,7 @@ export class Button extends Component<ButtonProps> { | |
source: true | ||
} | ||
}), | ||
color: prop.string( { | ||
color: prop.string<Button, ColorType>( { | ||
attribute: { | ||
source: true | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"version": "1.2.0", | ||
"main": "dist/main.js", | ||
"license": "MIT", | ||
"typings": "definitions/index.d.ts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add it also to template https://github.com/wc-catalogue/blaze-elements/blob/master/toolbelt/templates/package.json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is up to discussion, because current build is non existent till #153 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well template should reflect desired state for each package, also it doesn't have to do anything with our current build if definitions are not working it shouldn't be here as well. Simply I want to have package.json to be auto generated to some degree so we can easily change tooling for all packages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My comment was about the path of typings within package.json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"scripts": { | ||
"start": "../../node_modules/.bin/webpack-dev-server --config ../../webpack.config.js --env.dev --hot --host 0.0.0.0 --env.element=button", | ||
"test": "npm run build:test && ../../node_modules/.bin/wct -l firefox", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as 👆 |
||
"declaration": true, | ||
"declarationDir": "definitions" | ||
}, | ||
"include": [ | ||
"../../global.d.ts", | ||
"*.ts", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"declarationDir": "definitions" | ||
}, | ||
"include": [ | ||
"../../global.d.ts", | ||
"*.ts", | ||
"*.tsx" | ||
] | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we use
<bl-button>
here? I know that it's stated here https://github.com/wc-catalogue/blaze-elements/blob/master/docs/styleguides/TESTING.md#example--button- but I did forgot why.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups sorry forgot back ticks around the tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 still waiting for an answear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't remember either ¯_(ツ)_/¯
maybe few suggestions about your review attitude:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then please fix it to
<bl-button>
thanks
p.s. this tone of suggestion is really unfortunate, point of PR is answering questions. PR comments are not the right place for discussing attitudes and any PR unrelated topic. Please contact me directly if you want to discuss this further. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pls unblock merging of this PR. You are blocking rest of the team. thx