diff --git a/.gitignore b/.gitignore index 5d710721..2e55cf78 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ test-ts yarn.lock package-lock.json .vscode -preact/ +/preact/ .eslintcache diff --git a/package.json b/package.json index 07d8905a..7f9c89d9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "kcd-scripts": "^0.36.0", "node": "^8.9.4", "npm-run-all": "^4.1.2", - "preact": "^8.2.7", + "preact": "^8.2.9", "preval.macro": "^1.0.2", "prop-types": "^15.5.10", "react": "^16.2.0", diff --git a/src/__tests__/__snapshots__/typescript.js.snap b/src/__tests__/__snapshots__/typescript.js.snap index 47ac6a71..61b4ff52 100644 --- a/src/__tests__/__snapshots__/typescript.js.snap +++ b/src/__tests__/__snapshots__/typescript.js.snap @@ -1,6 +1,93 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Typescript: Typescript expected failures 1`] = ` +exports[`Typescript Preact: Typescript expected failures 1`] = ` +"test/preact/should-fail.test.tsx(9,61): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(13,66): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(17,68): error TS2345: Argument of type '() => { fillRule: string; }' is not assignable to parameter of type 'StyleArgument'. + Type '() => { fillRule: string; }' is not assignable to type '(string | SVGProperties | StyleFunction)[]'. + Property 'push' is missing in type '() => { fillRule: string; }'. +test/preact/should-fail.test.tsx(23,61): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ float: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(27,66): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ float: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(31,64): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument'. + Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'push' is missing in type '() => { float: string; }'. +test/preact/should-fail.test.tsx(35,69): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument'. + Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'push' is missing in type '() => { float: string; }'. +test/preact/should-fail.test.tsx(49,55): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(53,57): error TS2345: Argument of type '() => { fillRule: string; }' is not assignable to parameter of type 'StyleArgument'. + Type '() => { fillRule: string; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'push' is missing in type '() => { fillRule: string; }'. +test/preact/should-fail.test.tsx(57,61): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ float: \\"cat\\"; }'. +test/preact/should-fail.test.tsx(61,64): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument'. + Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'push' is missing in type '() => { float: string; }'. +test/preact/should-fail.test.tsx(79,26): error TS2551: Property 'colors' does not exist on type 'ExampleTheme'. Did you mean 'color'? +test/preact/should-fail.test.tsx(90,47): error TS2344: Type 'PropsWithoutTheme' does not satisfy the constraint '{ theme: any; }'. + Property 'theme' is missing in type 'PropsWithoutTheme'. +test/preact/should-fail.test.tsx(98,11): error TS2345: Argument of type 'FunctionalComponent' is not assignable to parameter of type '\\"tspan\\"'. +test/preact/should-fail.test.tsx(113,18): error TS2551: Property 'visibles' does not exist on type '{ theme: any; } & ExampleComponentProps & object'. Did you mean 'visible'? +test/preact/should-fail.test.tsx(125,29): error TS2322: Type '{ visible: string; }' is not assignable to type 'Readonly'. + Type '{ allowReorder: boolean; }' is not assignable to type '(string | SVGProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ allowReorder: boolean; }'. +test/preact/should-fail.test.tsx(133,18): error TS2345: Argument of type '{ color: boolean; }' is not assignable to parameter of type 'StyleArgument'. + Type '{ color: boolean; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'length' is missing in type '{ color: boolean; }'. +test/preact/should-fail.test.tsx(137,4): error TS2345: Argument of type 'FunctionalComponent' is not assignable to parameter of type '\\"tspan\\"'. +test/preact/should-fail.test.tsx(137,22): error TS7006: Parameter 'props' implicitly has an 'any' type. +test/preact/should-fail.test.tsx(142,12): error TS2365: Operator '===' cannot be applied to types 'boolean' and '\\"\\"'. +test/preact/should-fail.test.tsx(157,15): error TS2551: Property 'colors' does not exist on type 'ShouldClassNameUpdateProps'. Did you mean 'color'? +test/preact/should-fail.test.tsx(164,35): error TS2345: Argument of type 'FunctionalComponent' is not assignable to parameter of type '\\"tspan\\"'. +test/preact/should-fail.test.tsx(182,17): error TS2551: Property 'colors' does not exist on type 'ShouldClassNameUpdateContext'. Did you mean 'color'? +test/preact/should-fail.test.tsx(191,11): error TS2345: Argument of type '\\"div\\"' is not assignable to parameter of type '\\"tspan\\"'. +test/preact/should-fail.test.tsx(197,4): error TS2345: Argument of type '(props: { visible: boolean; }) => { primaryColor: boolean; }' is not assignable to parameter of type 'StyleArgument'. + Type '(props: { visible: boolean; }) => { primaryColor: boolean; }' is not assignable to type '(string | CSSProperties | StyleFunction)[]'. + Property 'push' is missing in type '(props: { visible: boolean; }) => { primaryColor: boolean; }'. +test/preact/should-fail.test.tsx(201,1): error TS2554: Expected 1 arguments, but got 0. +test/preact/should-fail.test.tsx(202,30): error TS2345: Argument of type '\\"\\"' is not assignable to parameter of type 'object'. +test/preact/should-fail.test.tsx(203,30): error TS2345: Argument of type 'false' is not assignable to parameter of type 'object'. +test/preact/should-fail.test.tsx(225,19): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly & Pick<{ theme?: any; }, never> & { ...'. +test/preact/should-fail.test.tsx(226,19): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly & Pick<{ theme?: any; }, never> & { ...'. + Types of property 'primaryColor' are incompatible. + Type 'number' is not assignable to type 'string | undefined'. +test/preact/should-fail.test.tsx(227,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly & Pick<{ theme: any; }, never> & ExtraGlamorousProps ...'. +test/preact/should-fail.test.tsx(228,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly & Pick<{ theme: any; }, never> & ExtraGlamorousProps ...'. + Types of property 'primaryColor' are incompatible. + Type 'number' is not assignable to type 'string | undefined'. +test/preact/should-fail.test.tsx(229,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly & ExtraGlamorousProps & Attributes & { child...'. +test/preact/should-fail.test.tsx(230,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly & ExtraGlamorousProps & Attributes & { child...'. + Types of property 'primaryColor' are incompatible. + Type 'number' is not assignable to type 'string | undefined'. +test/preact/should-fail.test.tsx(266,38): error TS2559: Type '{ display: string; }' has no properties in common with type 'Readonly'. Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction)[]'. Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'. diff --git a/src/__tests__/typescript.js b/src/__tests__/typescript.js index af1681d7..f081e095 100644 --- a/src/__tests__/typescript.js +++ b/src/__tests__/typescript.js @@ -1,6 +1,6 @@ import spawn from 'cross-spawn' -test('Typescript', () => { +test('Typescript React', () => { const typescriptCompilation = spawn.sync('./node_modules/.bin/tsc', [ '-p', './tsconfig.react.json', @@ -10,3 +10,14 @@ test('Typescript', () => { expect(output).toMatchSnapshot('Typescript expected failures') }) + +test('Typescript Preact', () => { + const typescriptCompilation = spawn.sync('./node_modules/.bin/tsc', [ + '-p', + './tsconfig.preact.json', + ]) + + const output = typescriptCompilation.stdout.toString() + + expect(output).toMatchSnapshot('Typescript expected failures') +}) diff --git a/test/preact/glamorous.test.tsx b/test/preact/glamorous.test.tsx new file mode 100644 index 00000000..4ed445c2 --- /dev/null +++ b/test/preact/glamorous.test.tsx @@ -0,0 +1,604 @@ +import {Component, h, FunctionalComponent} from 'preact' +import glamorous, {withTheme, ThemeProvider} from 'glamorous/preact' + +// Needed if generating definition files +// https://github.com/Microsoft/TypeScript/issues/5938 +import {GlamorousComponent, GlamorousComponentProps} from 'glamorous/preact' + +import {CSSPropertiesPseudo, CSSPropertiesLossy} from 'glamorous/preact' + +// Glamorous built in Components named exports + +import {Article, H1, P} from 'glamorous/preact' + +const useBuiltInNamedExports = ( +
+

Test

+

Built in components

+
+) + +// Properties +const Static = glamorous.div({ + fontSize: 20, + textAlign: 'center', + grid: 'auto-flow dense / 40px 40px 1fr', + gridTemplate: 'fit-content(100px) / fit-content(40%)', +}) + +// multi level nested properties + +glamorous.div({ + ':hover': { + '& .vendor-class': { + height: '10px', + }, + }, +}) + +glamorous.svg({ + ':hover': { + '& .vendor-class': { + height: '10px', + }, + }, +}) + +export interface StaticProps { + visible: boolean +} + +const StaticWithProps = glamorous.div(props => ({ + display: props.visible ? 'block' : 'none', +})) + +const useStatic = + +// Properties Array +glamorous.div({ + overflowWrap: 'break-word', + display: ['flex', 'block'], +}) + +glamorous.circle({ + textAlign: 'center', + display: ['marker', 'block'], +}) + +// pseudo and complex Properties +glamorous.div({ + ':active': { + fontSize: 10, + }, + '&:active': { + fontSize: 20, + textAlign: 'center', + }, +}) + +// classname string style +const Classname = glamorous.div( + { + fontSize: 20, + textAlign: 'center', + }, + 'example', +) + +// StyleFunction +const StyleFunction = glamorous.h1<{color: string}>( + { + fontSize: '10px', + zIndex: 'auto', + }, + 'example', + props => ({ + color: props.color, + }), +) + +// withComponent +const ExampleWithComponent = Classname.withComponent('p') + +const OtherExampleWithComponent = StyleFunction.withComponent('p') + +const UseWithComponent = () => ( + + + +) + +const StyleFunctionUseColor = () => + +// StyleFunction Array return +const StyleFunctionArray = glamorous.h1<{color: string}>(props => [ + 'example', + { + color: props.color, + }, +]) + +// Style Array +const StyleArray = glamorous.h1<{color: string}>([ + 'example', + props => [ + 'example', + { + color: props.color, + }, + ], +]) + +// theme styles +const Divider = glamorous.span<{ + theme: {main: {color: string}} +}>( + { + fontSize: '10px', + zIndex: 'auto', + }, + ({theme}) => ({ + color: theme.main && theme.main.color, + }), +) + +// n-number of styles +const SpanDivider = glamorous.span<{ + theme: {awesome: string; main: string} +}>( + { + fontSize: '10px', + }, + ({theme}) => ({ + color: theme.awesome, + }), + { + fontWeight: 500, + }, + { + fontFamily: 'Roboto', + fontWeight: 500, + }, + ({theme}) => ({ + color: theme.main, + }), +) + +interface DividerInsideDividerProps { + color: string +} + +// component styles +const DividerInsideDivider = glamorous(Divider)<{ + visible: boolean +}>(({visible}) => ({ + display: visible ? 'block' : 'none', +})) + +const DividerInsideDividerWithTheme = glamorous(Divider)<{ + visible: boolean + theme: {main: {color: string}} +}>( + { + fontSize: '10px', + }, + ({visible, theme}) => ({ + display: visible ? 'block' : 'none', + color: theme.main.color, + }), +) + +const theme = { + main: { + color: 'red', + }, +} + +export const Balloon = () => ( + + + + + + Static + Hello + + + +) + +export class AirBalloon extends Component<{}, {}> { + private spanElem: HTMLSpanElement + + public render() { + return ( + { + this.spanElem = c + }} + > + Hello + Span Divider + + ) + } +} + +class Test extends Component { + private div: HTMLDivElement + render() { + return ( +
{ + this.div = c + }} + /> + ) + } +} + +// React Class Wrapped Component + +interface ClassToWrapProps { + className: string + test: number +} + +class ClassToWrap extends Component { + render() { + return
+ } +} + +const WrappedClass = glamorous(ClassToWrap)({}) + +const useWrappedClass = + +// React Stateless Wrapped Component + +export interface WrappedStatelessProps { + theme: { + visible: boolean + } +} + +const StatelessToWrap: FunctionalComponent = () =>
+ +const WrappedStateless = glamorous(StatelessToWrap)( + props => ({ + display: props.theme.visible ? 'block' : 'none', + }), +) + +// Exported Component (for testing declaration generation) +export const ExportTest = glamorous.div({}) + +// Theme Provider + +interface ExampleTheme { + color: string +} + +const exampleTheme: ExampleTheme = { + color: 'red', +} + +const ThemedComponent = glamorous.h1<{theme: ExampleTheme}>( + { + fontSize: '10px', + }, + ({theme}) => ({ + color: theme ? theme.color : 'blue', + }), +) + +export const ThemeProviderAndThemedComponent = () => ( + + + +) + +// Glamorous component using general prop + +const props: GlamorousComponentProps = { + name: 'button', + onClick: () => {}, +} + +const GlamorousButton = glamorous.button({ + fontSize: '10px', +}) + +const UseGlamorousButtonWithGlamorousComponentProps = ( + +) + +// Extended component with theme prop + +interface ExampleTheme { + color: string +} + +interface Props { + title: string + theme: ExampleTheme +} + +const ComponentWithTheme: FunctionalComponent = props => ( +

+ {props.title} +

+) + +const NonGlamorousThemedComponent = withTheme(ComponentWithTheme) + +const NonGlamorousAlsoThemedComponent = withTheme(ComponentWithTheme) + +const UseNonGlamorousThemedComponent = ( +
+ + +
+) + +// displayName + +const TestDisplayName: FunctionalComponent = () =>
+ +glamorous(TestDisplayName, { + displayName: 'example', +}) + +// custom glamorous component factory + +interface ExampleComponentProps { + visible: boolean +} + +const ExampleComponent: FunctionalComponent = () => ( +
+) + +const StyledExampleComponent = glamorous(ExampleComponent)(props => ({ + display: props.visible ? 'none' : 'block', +})) + +const StyledExampleComponentHTMLKey = glamorous<{visible: boolean}>('div')( + props => ({ + display: props.visible ? 'none' : 'block', + }), +) + +const StyledExampleComponentSVGKey = glamorous<{visible: boolean}>('circle')( + { + fill: 'black', + }, + props => ({ + display: props.visible ? 'none' : 'block', + }), +) + +glamorous('circle')({allowReorder: 'yes'}) +glamorous('div')({color: 'red'}) + +const usingStyledExampleComponent = ( +
+ + + + +
+) + +// shouldClassNameUpdate + +interface ShouldClassNameUpdateProps { + color: string +} + +const TestShouldClassNameUpdate: FunctionalComponent< + ShouldClassNameUpdateProps +> = () =>
+ +const pureDivFactory = glamorous(TestShouldClassNameUpdate, { + shouldClassNameUpdate: (props, previousProps, context, previousContext) => { + if (props.color !== props.color) { + return false + } + return true + }, +}) + +interface ShouldClassNameUpdateContext { + color: string +} + +const pureDivFactory2 = glamorous< + ShouldClassNameUpdateProps, + ShouldClassNameUpdateContext +>(TestShouldClassNameUpdate, { + shouldClassNameUpdate: (props, previousProps, context, previousContext) => { + if (context.color !== previousContext.color) { + return false + } + + return true + }, +}) + +const PureDiv = pureDivFactory({marginLeft: 1}) + +// withProps + +const WithPropsDiv = glamorous('div', { + withProps: {primaryColor: 'red'}, +})(props => ({ + color: props.primaryColor, +})) + +const SimpleComponent = () =>
+ +const WithPropsSimpleComponent = glamorous(SimpleComponent, { + withProps: {primaryColor: 'red'}, +})(props => ({ + color: props.primaryColor, +})) + +const MethodWithPropsComponent = glamorous(SimpleComponent)({}).withProps({ + primaryColor: 'red', +}) + +const useWithProps = ( +
+ + + + + + +
+) + +// propsAreCssOverrides + +const ComponentPropsAreCssOverides = glamorous(SimpleComponent, { + propsAreCssOverrides: true, +})({ + margin: 1, + fontSize: 1, +}) + +const DivPropsAreCssOverides = glamorous('div', {propsAreCssOverrides: true})({ + margin: 1, + fontSize: 1, +}) + +const usePropsAreCssOverrides = ( +
+ + +
+) + +import {Span, Div} from 'glamorous/preact' + +const testDiv: JSX.Element = ( +
+
+
+) + +const BuiltinSingleElement: JSX.Element = ( + {}} /> +) +const BuiltinSingleElementNamedExport: JSX.Element = ( + {}} /> +) + +const BuiltinSingleChild: JSX.Element = ( + + Hello, world! + +) + +const BuiltinMultipleChild: JSX.Element = ( + + Hello, + world! + +) + +const BuiltinStyledSingleElement: JSX.Element = + +const BuiltinStyledWithSingleChild: JSX.Element = ( + + Hello, world! + +) + +const BuiltinStyledWithMultipleChild: JSX.Element = ( + {}}> + Hello, + world! + +) + +const CustomStatelessComponent: FunctionalComponent<{}> = _props =>
+class CustomClassComponent extends Component<{}, {}> { + render() { + return null + } +} +const CustomGlamorousComponent = glamorous.div() +const CustomGlamorousComponent2 = glamorous('div')() +const CustomGlamorousComponent3 = glamorous(CustomGlamorousComponent)() +const BuiltinStyledComponentChildren: JSX.Element = ( + {}}> + {} + + + + + + +) +const BuiltinStyledWithPrimitivesChildren: JSX.Element = ( + + {null} + {false} + {true} + {undefined} + {5} + +) + +// Preact does not support fragments yet +// https://github.com/developit/preact/issues/946 +// const BuiltinStyledWithFragment: JSX.Element = ( +//
+// {}}> +// +// +// {}}> +// +// +//
+// ) + +const cssProps = { + ':active': { + color: 'purple', + }, +} + +const BuiltinStyledWithCSSPseudoProps = ( +
+ + +
+) + +const nestedCssProps = [ + {color: 'red'}, + () => ({fontSize: 123}), + () => () => () => [{border: '1px solid black'}], +] + +const NestedStyleFunctions = ( +
+ +
+) diff --git a/test/preact/should-fail.test.tsx b/test/preact/should-fail.test.tsx new file mode 100644 index 00000000..9e8b3d07 --- /dev/null +++ b/test/preact/should-fail.test.tsx @@ -0,0 +1,273 @@ +import {Component, h, FunctionalComponent} from 'preact' + +import glamorous, {withTheme, ThemeProvider} from 'glamorous/preact' + +// built-in DOM component factories + +// ### SVG + +const BuiltInStrictSVGStyleObjectInvalidKey = glamorous.svg({ + fillRule: 'cat', +}) + +const BuiltInStrictSVGStyleObjectInvalidProperty = glamorous.svg({ + fillRule: 'cat', +}) + +const BuiltInStrictSVGStyleFunctionInvalidProperty = glamorous.svg(() => ({ + fillRule: 'cat', +})) + +// ### HTML + +const BuiltInStrictDIVtyleObjectInvlalidKey = glamorous.div({ + float: 'cat', +}) + +const BuiltInStrictDIVtyleObjectInvlalidProperty = glamorous.div({ + float: 'cat', +}) + +const BuiltInStrictDIVStyleFunctionInvlalidKey = glamorous.div(() => ({ + float: 'cat', +})) + +const BuiltInStrictDIVStyleFunctionInvlalidProperty = glamorous.div(() => ({ + float: 'cat', +})) + +// self provided glamorousComponentFactory + +interface TestComponentProps { + className: string +} + +const TestComponent: FunctionalComponent = props => ( +
+) + +const StrictSVGStyleObject = glamorous(TestComponent)({ + fillRule: 'cat', +}) + +const StrictSVGStyleFunction = glamorous(TestComponent)(() => ({ + fillRule: 'cat', +})) + +const BuiltInStrictStyleFunction = glamorous(TestComponent)({ + float: 'cat', +}) + +const BuiltInStrictDivStyleFunction = glamorous(TestComponent)(() => ({ + float: 'cat', +})) + +// Theme + +interface ExampleTheme { + color: string +} + +interface ThemeProps { + title: string + theme: ExampleTheme +} + +const ComponentWithTheme: FunctionalComponent = props => ( +

+ {props.title} +

+) + +interface PropsWithoutTheme { + title: string +} + +const NonGlamorousThemedComponent = withTheme( + ComponentWithTheme, +) + +// displayName + +const TestDisplayName: FunctionalComponent = () =>
+ +glamorous(TestDisplayName, { + displayName: 0, +}) + +// custom glamorous component factory + +interface ExampleComponentProps { + visible: boolean +} + +const ExampleComponent: FunctionalComponent = () => ( +
+) + +glamorous(ExampleComponent)(props => ({ + display: props.visibles ? 'none' : 'hidden', +})) + +glamorous<{visible: boolean}>('div')(props => ({ + display: props.visible ? 'none' : 'hidden', +})) + +const StyledExampleComponent = glamorous(ExampleComponent)() +const StyledExampleComponentKey = glamorous<{visible: boolean}>('div')() + +const usingStyledExampleComponent = ( +
+ + + + +
+) + +glamorous('circle')({allowReorder: false}) +glamorous('div')({color: false}) + +glamorous<{ + visible: string +}>(ExampleComponent)(props => ({ + display: props.visible ? 'none' : 'hidden', +})) + +glamorous<{visible: boolean}>('div')(props => ({ + display: props.visible === '' ? 'none' : 'hidden', +})) + +// shouldClassNameUpdate + +interface ShouldClassNameUpdateProps { + color: string +} + +const TestShouldClassNameUpdate: FunctionalComponent< + ShouldClassNameUpdateProps +> = () =>
+ +const pureDivFactory0 = glamorous(TestShouldClassNameUpdate, { + shouldClassNameUpdate: (props, previousProps, context, previousContext) => { + if (props.colors !== props.color) { + return false + } + return true + }, +}) + +const pureDivFactory1 = glamorous(TestShouldClassNameUpdate, { + shouldClassNameUpdate: (props, previousProps, context, previousContext) => { + if (props.color !== props.color) { + return false + } + return 1 + }, +}) + +interface ShouldClassNameUpdateContext { + color: string +} + +const pureDivFactory2 = glamorous< + ShouldClassNameUpdateProps, + ShouldClassNameUpdateContext +>(TestShouldClassNameUpdate, { + shouldClassNameUpdate: (props, previousProps, context, previousContext) => { + if (context.colors !== previousContext.color) { + return false + } + + return true + }, +}) + +// withProps +glamorous('div', { + withProps: '', +}) + +glamorous('div', { + withProps: {visible: false}, +})(props => ({ + primaryColor: props.visible, +})) + +glamorous('div')().withProps() +glamorous('div')().withProps('') +glamorous('div')().withProps(false) + +const WithPropsDiv = glamorous('div', { + withProps: {primaryColor: 'red'}, +})(props => ({ + primaryColor: props.primaryColor, +})) + +const SimpleComponent = () =>
+ +const MethodWithPropsComponent = glamorous(SimpleComponent)({}).withProps({ + primaryColor: 'red', +}) + +const WithPropsSimpleComponent = glamorous(SimpleComponent, { + withProps: {primaryColor: 'red'}, +})(props => ({ + primaryColor: props.primaryColor, +})) + +const useWithProps = ( +
+ + + + + + +
+) + +// Properties Array +glamorous.div({ + textAlign: 'center', + display: ['block', 'flexs'], +}) + +glamorous.circle({ + textAlign: 'center', + display: ['flexs', 'block'], +}) + +// propsAreCssOverrides + +const ComponentPropsAreCssOverides = glamorous(SimpleComponent, { + propsAreCssOverrides: true, +})({}) +const ComponentPropsAreNotCssOverides = glamorous(SimpleComponent, { + propsAreCssOverrides: false, +})({}) +const ComponentPropsAreAlsoNotCssOverides = glamorous(SimpleComponent)({}) + +const DivPropsAreCssOverides = glamorous('div', {propsAreCssOverrides: true})( + {}, +) +const DivPropsAreNotCssOverides = glamorous('div', { + propsAreCssOverrides: false, +})({}) +const DivPropsAreAlsoNotCssOverides = glamorous('div')({}) + +const usePropsAreCssOverrides = ( +
+ + + + + + + +
+) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..9ec9817c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "baseUrl": ".", + "jsx": "preserve", + "jsxFactory": "h", + "paths": { + "glamorous/preact": ["typings/preact/glamorous.d.ts"] + }, + "types": ["preact"] + }, + "include": ["test/preact/**/*", "typings/preact/**/*"], + "exclude": ["**/react/**/*"] +} diff --git a/tsconfig.preact.json b/tsconfig.preact.json new file mode 100644 index 00000000..1851d9b1 --- /dev/null +++ b/tsconfig.preact.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "baseUrl": ".", + "jsx": "preserve", + "jsxFactory": "h", + "paths": { + "glamorous/preact": ["typings/preact/glamorous.d.ts"], + "preact": ["node_modules/preact"] + }, + "types": ["preact"] + }, + "include": ["test/preact/*", "typings/preact/*"], + "exclude": ["**/react/**/*"] +} diff --git a/tsconfig.react.json b/tsconfig.react.json index c58b655a..a033ffce 100644 --- a/tsconfig.react.json +++ b/tsconfig.react.json @@ -1,4 +1,8 @@ { "extends": "./tsconfig.base.json", + "compilerOptions": { + "types": ["react"] + }, + "include": ["test/*", "typings/*"], "exclude": ["typings/preact"] } diff --git a/typings/preact/built-in-component-factories.d.ts b/typings/preact/built-in-component-factories.d.ts new file mode 100644 index 00000000..c8ea8aa1 --- /dev/null +++ b/typings/preact/built-in-component-factories.d.ts @@ -0,0 +1,153 @@ +import {SVGProperties} from './svg-properties' +import {CSSProperties} from './css-properties' +import {BuiltInGlamorousComponentFactory} from './component-factory' + +export type HTMLGlamorousComponentFactory< + HTMLElement +> = BuiltInGlamorousComponentFactory + +export type SVGGlamorousComponentFactory< + SVGElement +> = BuiltInGlamorousComponentFactory + +export interface HTMLComponentFactory { + a: HTMLGlamorousComponentFactory + abbr: HTMLGlamorousComponentFactory + address: HTMLGlamorousComponentFactory + area: HTMLGlamorousComponentFactory + article: HTMLGlamorousComponentFactory + aside: HTMLGlamorousComponentFactory + audio: HTMLGlamorousComponentFactory + b: HTMLGlamorousComponentFactory + base: HTMLGlamorousComponentFactory + bdi: HTMLGlamorousComponentFactory + bdo: HTMLGlamorousComponentFactory + big: HTMLGlamorousComponentFactory + blockquote: HTMLGlamorousComponentFactory + body: HTMLGlamorousComponentFactory + br: HTMLGlamorousComponentFactory + button: HTMLGlamorousComponentFactory + canvas: HTMLGlamorousComponentFactory + caption: HTMLGlamorousComponentFactory + cite: HTMLGlamorousComponentFactory + code: HTMLGlamorousComponentFactory + col: HTMLGlamorousComponentFactory + colgroup: HTMLGlamorousComponentFactory + data: HTMLGlamorousComponentFactory + datalist: HTMLGlamorousComponentFactory + dd: HTMLGlamorousComponentFactory + del: HTMLGlamorousComponentFactory + details: HTMLGlamorousComponentFactory + dfn: HTMLGlamorousComponentFactory + dialog: HTMLGlamorousComponentFactory + div: HTMLGlamorousComponentFactory + dl: HTMLGlamorousComponentFactory + dt: HTMLGlamorousComponentFactory + em: HTMLGlamorousComponentFactory + embed: HTMLGlamorousComponentFactory + fieldset: HTMLGlamorousComponentFactory + figcaption: HTMLGlamorousComponentFactory + figure: HTMLGlamorousComponentFactory + footer: HTMLGlamorousComponentFactory + form: HTMLGlamorousComponentFactory + h1: HTMLGlamorousComponentFactory + h2: HTMLGlamorousComponentFactory + h3: HTMLGlamorousComponentFactory + h4: HTMLGlamorousComponentFactory + h5: HTMLGlamorousComponentFactory + h6: HTMLGlamorousComponentFactory + head: HTMLGlamorousComponentFactory + header: HTMLGlamorousComponentFactory + hgroup: HTMLGlamorousComponentFactory + hr: HTMLGlamorousComponentFactory + html: HTMLGlamorousComponentFactory + i: HTMLGlamorousComponentFactory + iframe: HTMLGlamorousComponentFactory + img: HTMLGlamorousComponentFactory + input: HTMLGlamorousComponentFactory + ins: HTMLGlamorousComponentFactory + kbd: HTMLGlamorousComponentFactory + keygen: HTMLGlamorousComponentFactory + label: HTMLGlamorousComponentFactory + legend: HTMLGlamorousComponentFactory + li: HTMLGlamorousComponentFactory + link: HTMLGlamorousComponentFactory + main: HTMLGlamorousComponentFactory + map: HTMLGlamorousComponentFactory + mark: HTMLGlamorousComponentFactory + menu: HTMLGlamorousComponentFactory + menuitem: HTMLGlamorousComponentFactory + meta: HTMLGlamorousComponentFactory + meter: HTMLGlamorousComponentFactory + nav: HTMLGlamorousComponentFactory + noscript: HTMLGlamorousComponentFactory + object: HTMLGlamorousComponentFactory + ol: HTMLGlamorousComponentFactory + optgroup: HTMLGlamorousComponentFactory + option: HTMLGlamorousComponentFactory + output: HTMLGlamorousComponentFactory + p: HTMLGlamorousComponentFactory + param: HTMLGlamorousComponentFactory + picture: HTMLGlamorousComponentFactory + pre: HTMLGlamorousComponentFactory + progress: HTMLGlamorousComponentFactory + q: HTMLGlamorousComponentFactory + rp: HTMLGlamorousComponentFactory + rt: HTMLGlamorousComponentFactory + ruby: HTMLGlamorousComponentFactory + s: HTMLGlamorousComponentFactory + samp: HTMLGlamorousComponentFactory + script: HTMLGlamorousComponentFactory + section: HTMLGlamorousComponentFactory + select: HTMLGlamorousComponentFactory + small: HTMLGlamorousComponentFactory + source: HTMLGlamorousComponentFactory + span: HTMLGlamorousComponentFactory + strong: HTMLGlamorousComponentFactory + style: HTMLGlamorousComponentFactory + sub: HTMLGlamorousComponentFactory + summary: HTMLGlamorousComponentFactory + sup: HTMLGlamorousComponentFactory + table: HTMLGlamorousComponentFactory + tbody: HTMLGlamorousComponentFactory + td: HTMLGlamorousComponentFactory + textarea: HTMLGlamorousComponentFactory + tfoot: HTMLGlamorousComponentFactory + th: HTMLGlamorousComponentFactory + thead: HTMLGlamorousComponentFactory + time: HTMLGlamorousComponentFactory + title: HTMLGlamorousComponentFactory + tr: HTMLGlamorousComponentFactory + track: HTMLGlamorousComponentFactory + u: HTMLGlamorousComponentFactory + ul: HTMLGlamorousComponentFactory + var: HTMLGlamorousComponentFactory + video: HTMLGlamorousComponentFactory + wbr: HTMLGlamorousComponentFactory +} + +export type HTMLKey = keyof HTMLComponentFactory + +export interface SVGComponentFactory { + circle: SVGGlamorousComponentFactory + clipPath: SVGGlamorousComponentFactory + defs: SVGGlamorousComponentFactory + ellipse: SVGGlamorousComponentFactory + g: SVGGlamorousComponentFactory + image: SVGGlamorousComponentFactory + line: SVGGlamorousComponentFactory + linearGradient: SVGGlamorousComponentFactory + mask: SVGGlamorousComponentFactory + path: SVGGlamorousComponentFactory + pattern: SVGGlamorousComponentFactory + polygon: SVGGlamorousComponentFactory + polyline: SVGGlamorousComponentFactory + radialGradient: SVGGlamorousComponentFactory + rect: SVGGlamorousComponentFactory + stop: SVGGlamorousComponentFactory + svg: SVGGlamorousComponentFactory + text: SVGGlamorousComponentFactory + tspan: SVGGlamorousComponentFactory +} + +export type SVGKey = keyof SVGComponentFactory diff --git a/typings/preact/built-in-glamorous-components.d.ts b/typings/preact/built-in-glamorous-components.d.ts new file mode 100644 index 00000000..86b61c7b --- /dev/null +++ b/typings/preact/built-in-glamorous-components.d.ts @@ -0,0 +1,763 @@ +import {ExtraGlamorousProps} from './glamorous-component' +import { + CSSPropertiesCompleteSingle, + CSSPropertiesPseudo, +} from './css-properties' +import {SVGPropertiesCompleteSingle} from './svg-properties' + +// The file `./named-built-in-glamorous-components.d.ts` is based off this file +// and should get any updates this file does. + +/* + * FIXME: + * Since TypeScript doesn't have + * HTMLDetailsElement, HTMLDialogElement, + * HTMLKeygenElement, HTMLMenuItemElement + * Those components currently has wrong type. + * After TypeScript add those types, plz fix this. + * Reference: https://github.com/Microsoft/TypeScript/issues/17828 + */ +export interface HTMLComponent { + A: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Abbr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Address: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Area: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Article: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Aside: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Audio: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + B: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Base: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Bdi: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Bdo: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Big: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Blockquote: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Body: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Br: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Button: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Canvas: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Caption: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Cite: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Code: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Col: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Colgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Data: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Datalist: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Dd: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Del: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + // TypeScript doesn't have HTMLDetailsElement + Details: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Dfn: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + // TypeScript doesn't have HTMLDialogElement + Dialog: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Div: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Dl: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Dt: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Em: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Embed: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Fieldset: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Figcaption: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Figure: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Footer: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Form: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H1: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H2: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H3: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H4: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H5: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + H6: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Head: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Header: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Hgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Hr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Html: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + I: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Iframe: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Img: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Input: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Ins: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Kbd: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + // TypeScript doesn't have HTMLKeygenElement + Keygen: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Label: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Legend: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Li: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Link: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Main: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Map: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Mark: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Menu: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + // TypeScript doesn't have HTMLMenuItemElement + Menuitem: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Meta: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Meter: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Nav: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Noscript: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Object: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Ol: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Optgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Option: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Output: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + P: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Param: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Picture: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Pre: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Progress: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Q: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Rp: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Rt: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Ruby: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + S: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Samp: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Script: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Section: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Select: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Small: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Source: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Span: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Strong: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Style: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Sub: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Summary: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Sup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Table: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Tbody: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Td: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Textarea: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Tfoot: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Th: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Thead: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Time: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Title: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Tr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Track: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + U: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Ul: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Var: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Video: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > + Wbr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes + > +} + +export interface SVGComponent { + Circle: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + ClipPath: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Defs: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Ellipse: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + G: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Image: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Line: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + LinearGradient: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Mask: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Path: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Pattern: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Polygon: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Polyline: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + RadialGradient: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Rect: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Stop: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Svg: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Text: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > + Tspan: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes + > +} diff --git a/typings/preact/component-factory.d.ts b/typings/preact/component-factory.d.ts new file mode 100644 index 00000000..4df63398 --- /dev/null +++ b/typings/preact/component-factory.d.ts @@ -0,0 +1,141 @@ +import {GlamorousComponent} from './glamorous-component' +import {Omit} from './helpers' + +import {StyleArgument, StaticStyleArgument} from './style-arguments' + +// # built-in DOM - component factories glamorous.div + +export interface BuiltInGlamorousComponentFactory { + (...styles: StaticStyleArgument[]): GlamorousComponent< + ElementProps, + object + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent & ElementProps, Props> + + (...styles: StyleArgument[]): GlamorousComponent< + Props & ElementProps, + Props + > +} + +// # dom tag - component factories glamorous('div') + +// ## without propsAreCssOverides + +export interface KeyGlamorousComponentFactory< + ElementProps, + Properties, + ExternalProps, + DefaultProps +> { + (...styles: StaticStyleArgument[]): GlamorousComponent< + ElementProps & ExternalProps & Partial, + ExternalProps + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ElementProps & + ExternalProps & + Partial & + Omit & + Props, + ExternalProps + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ElementProps & ExternalProps & Partial & Props, + ExternalProps + > +} + +// ## with propsAreCssOverides + +export interface KeyGlamorousComponentFactoryCssOverides< + ElementProps, + Properties, + ExternalProps, + DefaultProps +> { + (...styles: StaticStyleArgument[]): GlamorousComponent< + ElementProps & ExternalProps & Partial & Properties, + ExternalProps + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ElementProps & + ExternalProps & + Partial & + Omit & + Properties, + ExternalProps + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ElementProps & ExternalProps & Partial & Props & Properties, + ExternalProps + > +} + +// # react component - component factories glamorous(Component) + +// ## without propsAreCssOverides + +export interface GlamorousComponentFactory< + ExternalProps, + Properties, + DefaultProps +> { + (...styles: StaticStyleArgument[]): GlamorousComponent< + ExternalProps & Partial, + object + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ExternalProps & Partial & Omit, + Props + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent & Props, Props> +} + +// ## with propsAreCssOverides + +export interface GlamorousComponentFactoryCssOverides< + ExternalProps, + Properties, + DefaultProps +> { + (...styles: StaticStyleArgument[]): GlamorousComponent< + ExternalProps & Partial & Properties, + object + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ExternalProps & Partial & Properties & Omit, + Props + > + + ( + ...styles: StyleArgument[] + ): GlamorousComponent< + ExternalProps & Partial & Properties & Props, + Props + > +} diff --git a/typings/preact/css-properties.d.ts b/typings/preact/css-properties.d.ts new file mode 100644 index 00000000..92c7f905 --- /dev/null +++ b/typings/preact/css-properties.d.ts @@ -0,0 +1,39 @@ +import * as CSS from 'csstype' +import {SingleOrArray} from './helpers' + +export interface CSSPropertiesCompleteSingle + extends CSS.Properties {} + +export type CSSPropertiesPseudo = {[K in CSS.Pseudos]?: CSSProperties} + +type CSSPropertiesComplete = SingleOrArray< + CSSPropertiesCompleteSingle, + keyof CSSPropertiesCompleteSingle +> + +export interface CSSPropertiesLossy { + [propertyName: string]: + | string + | number + | CSSPropertiesComplete + | undefined + | Array + | CSSPropertiesLossy +} + +export interface CSSProperties + extends CSSPropertiesComplete, + CSSPropertiesPseudo, + CSSPropertiesLossy {} + +export type CSSPropertiesRecursive = + | CSSProperties + | CSSPropertiesArray + | CSSFunction + +// TODO: This could be made generic. Issue PR if you're so inclined! +export interface CSSFunction { + (props: {}): CSSPropertiesRecursive +} + +export interface CSSPropertiesArray extends Array {} diff --git a/typings/preact/dom-tag-component-factory.d.ts b/typings/preact/dom-tag-component-factory.d.ts new file mode 100644 index 00000000..0ad64e8f --- /dev/null +++ b/typings/preact/dom-tag-component-factory.d.ts @@ -0,0 +1,337 @@ +import { + KeyGlamorousComponentFactory, + GlamorousOptions, + CSSProperties, + SVGProperties, + PropsAreCssOverridesGlamorousOptions, + KeyGlamorousComponentFactoryCssOverides, +} from './glamorous' + +export interface DOMTagGlamorousComponentFactory< + Key extends keyof HTMLDomTags +> { + ( + component: Key, + options?: Partial>, + ): KeyGlamorousComponentFactory< + JSX.HTMLAttributes, + CSSProperties, + ExternalProps, + DefaultProps + > + + ( + component: Key, + options?: PropsAreCssOverridesGlamorousOptions< + ExternalProps, + Context, + DefaultProps + >, + ): KeyGlamorousComponentFactoryCssOverides< + JSX.HTMLAttributes, + CSSProperties, + ExternalProps, + DefaultProps + > +} + +export interface SVGTagGlamorousComponentFactory { + ( + component: Key, + options?: Partial>, + ): KeyGlamorousComponentFactory< + JSX.SVGAttributes, + SVGProperties, + ExternalProps, + DefaultProps + > + + ( + component: Key, + options?: PropsAreCssOverridesGlamorousOptions< + ExternalProps, + Context, + DefaultProps + >, + ): KeyGlamorousComponentFactoryCssOverides< + JSX.SVGAttributes, + SVGProperties, + ExternalProps, + DefaultProps + > +} + +export interface DOMTagComponentFactory + extends DOMTagGlamorousComponentFactory<'a'>, + DOMTagGlamorousComponentFactory<'a'>, + DOMTagGlamorousComponentFactory<'abbr'>, + DOMTagGlamorousComponentFactory<'address'>, + DOMTagGlamorousComponentFactory<'area'>, + DOMTagGlamorousComponentFactory<'article'>, + DOMTagGlamorousComponentFactory<'aside'>, + DOMTagGlamorousComponentFactory<'audio'>, + DOMTagGlamorousComponentFactory<'b'>, + DOMTagGlamorousComponentFactory<'base'>, + DOMTagGlamorousComponentFactory<'bdi'>, + DOMTagGlamorousComponentFactory<'bdo'>, + DOMTagGlamorousComponentFactory<'big'>, + DOMTagGlamorousComponentFactory<'blockquote'>, + DOMTagGlamorousComponentFactory<'body'>, + DOMTagGlamorousComponentFactory<'br'>, + DOMTagGlamorousComponentFactory<'button'>, + DOMTagGlamorousComponentFactory<'canvas'>, + DOMTagGlamorousComponentFactory<'caption'>, + DOMTagGlamorousComponentFactory<'cite'>, + DOMTagGlamorousComponentFactory<'code'>, + DOMTagGlamorousComponentFactory<'col'>, + DOMTagGlamorousComponentFactory<'colgroup'>, + DOMTagGlamorousComponentFactory<'data'>, + DOMTagGlamorousComponentFactory<'datalist'>, + DOMTagGlamorousComponentFactory<'dd'>, + DOMTagGlamorousComponentFactory<'del'>, + DOMTagGlamorousComponentFactory<'details'>, + DOMTagGlamorousComponentFactory<'dfn'>, + DOMTagGlamorousComponentFactory<'dialog'>, + DOMTagGlamorousComponentFactory<'div'>, + DOMTagGlamorousComponentFactory<'dl'>, + DOMTagGlamorousComponentFactory<'dt'>, + DOMTagGlamorousComponentFactory<'em'>, + DOMTagGlamorousComponentFactory<'embed'>, + DOMTagGlamorousComponentFactory<'fieldset'>, + DOMTagGlamorousComponentFactory<'figcaption'>, + DOMTagGlamorousComponentFactory<'figure'>, + DOMTagGlamorousComponentFactory<'footer'>, + DOMTagGlamorousComponentFactory<'form'>, + DOMTagGlamorousComponentFactory<'h1'>, + DOMTagGlamorousComponentFactory<'h2'>, + DOMTagGlamorousComponentFactory<'h3'>, + DOMTagGlamorousComponentFactory<'h4'>, + DOMTagGlamorousComponentFactory<'h5'>, + DOMTagGlamorousComponentFactory<'h6'>, + DOMTagGlamorousComponentFactory<'head'>, + DOMTagGlamorousComponentFactory<'header'>, + DOMTagGlamorousComponentFactory<'hgroup'>, + DOMTagGlamorousComponentFactory<'hr'>, + DOMTagGlamorousComponentFactory<'html'>, + DOMTagGlamorousComponentFactory<'i'>, + DOMTagGlamorousComponentFactory<'iframe'>, + DOMTagGlamorousComponentFactory<'img'>, + DOMTagGlamorousComponentFactory<'input'>, + DOMTagGlamorousComponentFactory<'ins'>, + DOMTagGlamorousComponentFactory<'kbd'>, + DOMTagGlamorousComponentFactory<'keygen'>, + DOMTagGlamorousComponentFactory<'label'>, + DOMTagGlamorousComponentFactory<'legend'>, + DOMTagGlamorousComponentFactory<'li'>, + DOMTagGlamorousComponentFactory<'link'>, + DOMTagGlamorousComponentFactory<'main'>, + DOMTagGlamorousComponentFactory<'map'>, + DOMTagGlamorousComponentFactory<'mark'>, + DOMTagGlamorousComponentFactory<'menu'>, + DOMTagGlamorousComponentFactory<'menuitem'>, + DOMTagGlamorousComponentFactory<'meta'>, + DOMTagGlamorousComponentFactory<'meter'>, + DOMTagGlamorousComponentFactory<'nav'>, + DOMTagGlamorousComponentFactory<'noscript'>, + DOMTagGlamorousComponentFactory<'object'>, + DOMTagGlamorousComponentFactory<'ol'>, + DOMTagGlamorousComponentFactory<'optgroup'>, + DOMTagGlamorousComponentFactory<'option'>, + DOMTagGlamorousComponentFactory<'output'>, + DOMTagGlamorousComponentFactory<'p'>, + DOMTagGlamorousComponentFactory<'param'>, + DOMTagGlamorousComponentFactory<'picture'>, + DOMTagGlamorousComponentFactory<'pre'>, + DOMTagGlamorousComponentFactory<'progress'>, + DOMTagGlamorousComponentFactory<'q'>, + DOMTagGlamorousComponentFactory<'rp'>, + DOMTagGlamorousComponentFactory<'rt'>, + DOMTagGlamorousComponentFactory<'ruby'>, + DOMTagGlamorousComponentFactory<'s'>, + DOMTagGlamorousComponentFactory<'samp'>, + DOMTagGlamorousComponentFactory<'script'>, + DOMTagGlamorousComponentFactory<'section'>, + DOMTagGlamorousComponentFactory<'select'>, + DOMTagGlamorousComponentFactory<'small'>, + DOMTagGlamorousComponentFactory<'source'>, + DOMTagGlamorousComponentFactory<'span'>, + DOMTagGlamorousComponentFactory<'strong'>, + DOMTagGlamorousComponentFactory<'style'>, + DOMTagGlamorousComponentFactory<'sub'>, + DOMTagGlamorousComponentFactory<'summary'>, + DOMTagGlamorousComponentFactory<'sup'>, + DOMTagGlamorousComponentFactory<'table'>, + DOMTagGlamorousComponentFactory<'tbody'>, + DOMTagGlamorousComponentFactory<'td'>, + DOMTagGlamorousComponentFactory<'textarea'>, + DOMTagGlamorousComponentFactory<'tfoot'>, + DOMTagGlamorousComponentFactory<'th'>, + DOMTagGlamorousComponentFactory<'thead'>, + DOMTagGlamorousComponentFactory<'time'>, + DOMTagGlamorousComponentFactory<'title'>, + DOMTagGlamorousComponentFactory<'tr'>, + DOMTagGlamorousComponentFactory<'track'>, + DOMTagGlamorousComponentFactory<'u'>, + DOMTagGlamorousComponentFactory<'ul'>, + DOMTagGlamorousComponentFactory<'var'>, + DOMTagGlamorousComponentFactory<'video'>, + DOMTagGlamorousComponentFactory<'wbr'> {} + +export interface SVGTagComponentFactory + extends SVGTagGlamorousComponentFactory<'circle'>, + SVGTagGlamorousComponentFactory<'clipPath'>, + SVGTagGlamorousComponentFactory<'defs'>, + SVGTagGlamorousComponentFactory<'ellipse'>, + SVGTagGlamorousComponentFactory<'g'>, + SVGTagGlamorousComponentFactory<'image'>, + SVGTagGlamorousComponentFactory<'line'>, + SVGTagGlamorousComponentFactory<'linearGradient'>, + SVGTagGlamorousComponentFactory<'mask'>, + SVGTagGlamorousComponentFactory<'path'>, + SVGTagGlamorousComponentFactory<'pattern'>, + SVGTagGlamorousComponentFactory<'polygon'>, + SVGTagGlamorousComponentFactory<'polyline'>, + SVGTagGlamorousComponentFactory<'radialGradient'>, + SVGTagGlamorousComponentFactory<'rect'>, + SVGTagGlamorousComponentFactory<'stop'>, + SVGTagGlamorousComponentFactory<'svg'>, + SVGTagGlamorousComponentFactory<'text'>, + SVGTagGlamorousComponentFactory<'tspan'> {} + +export interface HTMLDomTags { + a: HTMLAnchorElement + abbr: HTMLElement + address: HTMLElement + area: HTMLAreaElement + article: HTMLElement + aside: HTMLElement + audio: HTMLAudioElement + b: HTMLElement + base: HTMLBaseElement + bdi: HTMLElement + bdo: HTMLElement + big: HTMLElement + blockquote: HTMLElement + body: HTMLBodyElement + br: HTMLBRElement + button: HTMLButtonElement + canvas: HTMLCanvasElement + caption: HTMLElement + cite: HTMLElement + code: HTMLElement + col: HTMLTableColElement + colgroup: HTMLTableColElement + data: HTMLElement + datalist: HTMLDataListElement + dd: HTMLElement + del: HTMLElement + details: HTMLElement + dfn: HTMLElement + dialog: HTMLElement + div: HTMLDivElement + dl: HTMLDListElement + dt: HTMLElement + em: HTMLElement + embed: HTMLEmbedElement + fieldset: HTMLFieldSetElement + figcaption: HTMLElement + figure: HTMLElement + footer: HTMLElement + form: HTMLFormElement + h1: HTMLHeadingElement + h2: HTMLHeadingElement + h3: HTMLHeadingElement + h4: HTMLHeadingElement + h5: HTMLHeadingElement + h6: HTMLHeadingElement + head: HTMLHeadElement + header: HTMLElement + hgroup: HTMLElement + hr: HTMLHRElement + html: HTMLHtmlElement + i: HTMLElement + iframe: HTMLIFrameElement + img: HTMLImageElement + input: HTMLInputElement + ins: HTMLModElement + kbd: HTMLElement + keygen: HTMLElement + label: HTMLLabelElement + legend: HTMLLegendElement + li: HTMLLIElement + link: HTMLLinkElement + main: HTMLElement + map: HTMLMapElement + mark: HTMLElement + menu: HTMLElement + menuitem: HTMLElement + meta: HTMLMetaElement + meter: HTMLElement + nav: HTMLElement + noscript: HTMLElement + object: HTMLObjectElement + ol: HTMLOListElement + optgroup: HTMLOptGroupElement + option: HTMLOptionElement + output: HTMLElement + p: HTMLParagraphElement + param: HTMLParamElement + picture: HTMLElement + pre: HTMLPreElement + progress: HTMLProgressElement + q: HTMLQuoteElement + rp: HTMLElement + rt: HTMLElement + ruby: HTMLElement + s: HTMLElement + samp: HTMLElement + script: HTMLElement + section: HTMLElement + select: HTMLSelectElement + small: HTMLElement + source: HTMLSourceElement + span: HTMLSpanElement + strong: HTMLElement + style: HTMLStyleElement + sub: HTMLElement + summary: HTMLElement + sup: HTMLElement + table: HTMLTableElement + tbody: HTMLTableSectionElement + td: HTMLTableDataCellElement + textarea: HTMLTextAreaElement + tfoot: HTMLTableSectionElement + th: HTMLTableHeaderCellElement + thead: HTMLTableSectionElement + time: HTMLElement + title: HTMLTitleElement + tr: HTMLTableRowElement + track: HTMLTrackElement + u: HTMLElement + ul: HTMLUListElement + var: HTMLElement + video: HTMLVideoElement + wbr: HTMLElement +} + +export interface SVGDomTags { + circle: SVGCircleElement + clipPath: SVGClipPathElement + defs: SVGDefsElement + ellipse: SVGEllipseElement + g: SVGGElement + image: SVGImageElement + line: SVGLineElement + linearGradient: SVGLinearGradientElement + mask: SVGMaskElement + path: SVGPathElement + pattern: SVGPatternElement + polygon: SVGPolygonElement + polyline: SVGPolylineElement + radialGradient: SVGRadialGradientElement + rect: SVGRectElement + stop: SVGStopElement + svg: SVGSVGElement + text: SVGTextElement + tspan: SVGTSpanElement +} diff --git a/typings/preact/glamorous-component.d.ts b/typings/preact/glamorous-component.d.ts new file mode 100644 index 00000000..2dd70869 --- /dev/null +++ b/typings/preact/glamorous-component.d.ts @@ -0,0 +1,60 @@ +import {CSSPropertiesRecursive} from './css-properties' + +import {Component} from './glamorous' + +import {Omit} from './helpers' + +import * as preact from 'preact' + +/** + * `glamorousComponentFactory` returns a ComponentClass + * + * @see {@link https://github.com/paypal/glamorous/blob/master/src/create-glamorous.js#L28-L131} + */ + +export interface ExtraGlamorousProps { + /** + * Called with the inner element's reference + */ + innerRef?: object | ((instance: any) => void) + + className?: string + /** + * Same type as any of the styles provided, will be merged with this component's styles and take highest priority over the component's predefined styles + */ + css?: CSSPropertiesRecursive + theme?: object +} + +export interface GlamorousComponentFunctions { + /** + * Copies the styles of an already created glamorous component with a different tag + */ + withComponent: ( + component: string | Component, + ) => GlamorousComponent + + /** + * Applies props by default for a component + */ + withProps: ( + props: DefaultProps, + ) => GlamorousComponent, Props> +} + +export interface GlamorousComponent + extends preact.ComponentConstructor, + GlamorousComponentFunctions {} + +interface IntrinsicAttributes { + key?: preact.Key +} +interface IntrinsicClassAttributes extends IntrinsicAttributes { + ref?: preact.Ref +} + +export type GlamorousComponentProps = IntrinsicAttributes & + IntrinsicClassAttributes< + preact.Component + > & + ExternalProps & {children?: JSX.Element} diff --git a/typings/preact/glamorous.d.ts b/typings/preact/glamorous.d.ts new file mode 100644 index 00000000..6659ae0f --- /dev/null +++ b/typings/preact/glamorous.d.ts @@ -0,0 +1,241 @@ +// Type definitions for Glamorous v3.2.0 +// Project: https://github.com/paypal/glamorous +// Definitions by: Kok Sam + +import * as preact from 'preact' +import {HTMLComponent, SVGComponent} from './built-in-glamorous-components' +import { + HTMLComponentFactory, + HTMLKey, + SVGComponentFactory, + SVGKey, +} from './built-in-component-factories' +import { + GlamorousComponent, + GlamorousComponentProps, + GlamorousComponentFunctions, + ExtraGlamorousProps, +} from './glamorous-component' +import { + BuiltInGlamorousComponentFactory, + KeyGlamorousComponentFactory, + KeyGlamorousComponentFactoryCssOverides, + GlamorousComponentFactory, + GlamorousComponentFactoryCssOverides, +} from './component-factory' +import { + CSSProperties, + CSSPropertiesCompleteSingle, + CSSPropertiesComplete, + CSSPropertiesPseudo, + CSSPropertiesLossy, +} from './css-properties' +import { + SVGProperties, + SVGPropertiesCompleteSingle, + SVGPropertiesComplete, + SVGPropertiesLossy, +} from './svg-properties' +import {StyleFunction, StyleArray, StyleArgument} from './style-arguments' +import { + DOMTagComponentFactory, + SVGTagComponentFactory, + HTMLDomTags, + SVGDomTags, + DOMTagGlamorousComponentFactory, + SVGTagGlamorousComponentFactory, +} from './dom-tag-component-factory' + +import {Omit} from './helpers' + +export { + CSSProperties, + CSSPropertiesCompleteSingle, + CSSPropertiesComplete, + CSSPropertiesPseudo, + CSSPropertiesLossy, + SVGProperties, + SVGPropertiesCompleteSingle, + SVGPropertiesComplete, + SVGPropertiesLossy, + GlamorousComponent, + GlamorousComponentProps, + GlamorousComponentFunctions, + ExtraGlamorousProps, + StyleFunction, + StyleArray, + StyleArgument, + BuiltInGlamorousComponentFactory, + KeyGlamorousComponentFactory, + KeyGlamorousComponentFactoryCssOverides, + GlamorousComponentFactory, + GlamorousComponentFactoryCssOverides, + HTMLComponent, + SVGComponent, + HTMLComponentFactory, + HTMLKey, + SVGComponentFactory, + SVGKey, + DOMTagComponentFactory, + SVGTagComponentFactory, + HTMLDomTags, + SVGDomTags, + DOMTagGlamorousComponentFactory, + SVGTagGlamorousComponentFactory, +} + +export interface GlamorousOptions { + /** + * Used by React in the React DevTools + */ + displayName: string + /** + * Applies the same logic to components (html/svg) for which props to forward as it does for the built-in factories + */ + rootEl: string | Element + /** + * Specifies extra props that should be forwarded and spread on the DOM element + */ + forwardProps: string[] + /** + * Specifies properties to filter out from being forwarded to the child components; Useful for components like react-router Link + */ + filterProps: string[] + /** + * Allows you to prevent glamor from computing your styles when you know the class name should not change. + */ + shouldClassNameUpdate: ( + props: Props, + prevProps: Props, + context: Context, + prevContext: Context, + ) => boolean + /** + * Allows you to use props as CSS + */ + propsAreCssOverrides?: false + /** + * Applies props by default for a component + */ + withProps: DefaultProps +} + +export interface PropsAreCssOverridesGlamorousOptions< + Props, + Context, + DefaultProps +> { + /** + * Used by React in the React DevTools + */ + displayName?: string + /** + * Applies the same logic to components (html/svg) for which props to forward as it does for the built-in factories + */ + rootEl?: string | Element + /** + * Specifies extra props that should be forwarded and spread on the DOM element + */ + forwardProps?: string[] + /** + * Specifies properties to filter out from being forwarded to the child components; Useful for components like react-router Link + */ + filterProps?: string[] + /** + * Allows you to prevent glamor from computing your styles when you know the class name should not change. + */ + shouldClassNameUpdate?: ( + props: Props, + prevProps: Props, + context: Context, + prevContext: Context, + ) => boolean + /** + * Allows you to use props as CSS + */ + propsAreCssOverrides: true + /** + * Applies props by default for a component + */ + withProps?: DefaultProps +} + +export type Component = + | preact.ComponentConstructor + | preact.FunctionalComponent + +type OmitInternals = Omit< + Props, + 'className' | 'theme' +> + +type GlamorousProps = {className?: string; theme?: object} + +export interface GlamorousInterface + extends HTMLComponentFactory, + SVGComponentFactory, + HTMLComponent, + SVGComponent, + DOMTagComponentFactory, + SVGTagComponentFactory { + // # Glamarous Component factories + + // Two overloads are needed per shape due to a union return of CSSProperties | SVGProperties + // resulting in a loss of typesafety on function arguments + + // ## create a component factory from your own component + + ( + component: Component, + options?: Partial>, + ): GlamorousComponentFactory + ( + component: Component, + options?: Partial>, + ): GlamorousComponentFactory + + ( + component: Component, + options?: PropsAreCssOverridesGlamorousOptions< + ExternalProps, + Context, + DefaultProps + >, + ): GlamorousComponentFactoryCssOverides< + ExternalProps, + CSSProperties, + DefaultProps + > + ( + component: Component, + options?: PropsAreCssOverridesGlamorousOptions< + ExternalProps, + Context, + DefaultProps + >, + ): GlamorousComponentFactoryCssOverides< + ExternalProps, + SVGProperties, + DefaultProps + > +} + +interface ThemeProps { + theme: object +} + +export abstract class ThemeProvider extends preact.Component {} + +export function withTheme( + component: preact.ComponentConstructor, +): preact.ComponentConstructor> + +export function withTheme( + component: preact.FunctionalComponent, +): preact.FunctionalComponent> + +export * from './named-built-in-glamorous-components' + +declare const glamorous: GlamorousInterface + +export default glamorous diff --git a/typings/preact/helpers.d.ts b/typings/preact/helpers.d.ts new file mode 100644 index 00000000..9c9245fc --- /dev/null +++ b/typings/preact/helpers.d.ts @@ -0,0 +1,8 @@ +type Diff = ({[P in T]: P} & + {[P in U]: never} & {[x: string]: never})[T] + +export type Omit = Pick> + +export type SingleOrArray = { + [P in T]: Properties[P] | Array +} diff --git a/typings/preact/named-built-in-glamorous-components.d.ts b/typings/preact/named-built-in-glamorous-components.d.ts new file mode 100644 index 00000000..3e903bea --- /dev/null +++ b/typings/preact/named-built-in-glamorous-components.d.ts @@ -0,0 +1,750 @@ +import * as preact from 'preact' +import {ExtraGlamorousProps} from './glamorous-component' +import { + CSSPropertiesCompleteSingle, + CSSPropertiesPseudo, +} from './css-properties' +import {SVGPropertiesCompleteSingle} from './svg-properties' + +// This file is based off `./built-in-glamorous-components.d.ts` + +// CSS tags + +export const A: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Abbr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Address: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Area: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Article: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Aside: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Audio: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const B: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Base: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Bdi: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Bdo: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Big: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Blockquote: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Body: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Br: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Button: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Canvas: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Caption: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Cite: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Code: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Col: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Colgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Data: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Datalist: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Dd: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Del: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Details: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Dfn: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Dialog: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Div: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Dl: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Dt: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Em: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Embed: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Fieldset: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Figcaption: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Figure: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Footer: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Form: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H1: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H2: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H3: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H4: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H5: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const H6: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Head: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Header: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Hgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Hr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Html: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const I: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Iframe: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Img: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Input: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Ins: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Kbd: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Keygen: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Label: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Legend: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Li: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Link: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Main: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Map: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Mark: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Menu: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Menuitem: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Meta: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Meter: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Nav: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Noscript: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Object: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Ol: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Optgroup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Option: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Output: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const P: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Param: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Picture: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Pre: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Progress: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Q: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Rp: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Rt: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Ruby: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const S: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Samp: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Script: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Section: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Select: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Small: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Source: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Span: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Strong: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Style: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Sub: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Summary: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Sup: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Table: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Tbody: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Td: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Textarea: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Tfoot: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Th: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Thead: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Time: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Title: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Tr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Track: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const U: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Ul: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Var: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Video: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> +export const Wbr: preact.FunctionalComponent< + CSSPropertiesCompleteSingle & + CSSPropertiesPseudo & + ExtraGlamorousProps & + JSX.HTMLAttributes +> + +// SVG tags + +export const Circle: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const ClipPath: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Defs: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Ellipse: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const G: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Image: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Line: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const LinearGradient: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Mask: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Path: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Pattern: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Polygon: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Polyline: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const RadialGradient: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Rect: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Stop: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Svg: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Text: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> +export const Tspan: preact.FunctionalComponent< + SVGPropertiesCompleteSingle & ExtraGlamorousProps & JSX.SVGAttributes +> diff --git a/typings/preact/style-arguments.d.ts b/typings/preact/style-arguments.d.ts new file mode 100644 index 00000000..6fbf774a --- /dev/null +++ b/typings/preact/style-arguments.d.ts @@ -0,0 +1,23 @@ +export interface StyleFunction { + (props: Props): + | Properties + | string + | Array> +} + +export type StyleArray = Array< + Properties | string | StyleFunction +> + +export type StaticStyleArray = Array + +export type StyleArgument = + | Properties + | string + | StyleFunction + | StyleArray + +export type StaticStyleArgument = + | Properties + | string + | StaticStyleArray diff --git a/typings/preact/svg-properties.d.ts b/typings/preact/svg-properties.d.ts new file mode 100644 index 00000000..ed0ce821 --- /dev/null +++ b/typings/preact/svg-properties.d.ts @@ -0,0 +1,24 @@ +import * as CSS from 'csstype' +import {SingleOrArray} from './helpers' + +export interface SVGPropertiesCompleteSingle + extends CSS.SvgProperties {} + +type SVGPropertiesComplete = SingleOrArray< + SVGPropertiesCompleteSingle, + keyof SVGPropertiesCompleteSingle +> + +export interface SVGPropertiesLossy { + [propertyName: string]: + | string + | number + | SVGProperties + | undefined + | Array + | SVGPropertiesLossy +} + +export interface SVGProperties + extends SVGPropertiesComplete, + SVGPropertiesLossy {}