@charcoal-ui/react 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/react",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -33,7 +33,7 @@
33
33
  "test": "vitest run --passWithNoTests"
34
34
  },
35
35
  "devDependencies": {
36
- "@charcoal-ui/esbuild-plugin-styled-components": "^4.0.1",
36
+ "@charcoal-ui/esbuild-plugin-styled-components": "^4.1.0",
37
37
  "@react-types/switch": "^3.1.2",
38
38
  "@storybook/addon-actions": "^8.0.5",
39
39
  "@storybook/react": "^8.0.5",
@@ -62,10 +62,10 @@
62
62
  "vitest": "^2.0.1"
63
63
  },
64
64
  "dependencies": {
65
- "@charcoal-ui/foundation": "^4.0.1",
66
- "@charcoal-ui/icons": "^4.0.1",
67
- "@charcoal-ui/theme": "^4.0.1",
68
- "@charcoal-ui/utils": "^4.0.1",
65
+ "@charcoal-ui/foundation": "^4.1.0",
66
+ "@charcoal-ui/icons": "^4.1.0",
67
+ "@charcoal-ui/theme": "^4.1.0",
68
+ "@charcoal-ui/utils": "^4.1.0",
69
69
  "@react-aria/button": "^3.9.1",
70
70
  "@react-aria/checkbox": "^3.13.0",
71
71
  "@react-aria/dialog": "^3.5.10",
@@ -98,5 +98,5 @@
98
98
  "url": "https://github.com/pixiv/charcoal.git",
99
99
  "directory": "packages/react"
100
100
  },
101
- "gitHead": "42466af3a62cb99358f735a2ce16b237591a2579"
101
+ "gitHead": "e1d401460774c73120434d8be3bca5698d519493"
102
102
  }
@@ -46,5 +46,11 @@ const Button = forwardRef(function Button<T extends React.ElementType>(
46
46
  ref={ref}
47
47
  />
48
48
  )
49
- }) as <T extends React.ElementType = 'button'>(p: ButtonProps<T>) => JSX.Element
49
+ }) as <T extends React.ElementType = 'button'>(
50
+ p: 'button' extends T
51
+ ? ButtonProps<'button'>
52
+ : ButtonProps<T> & {
53
+ component: T // required
54
+ }
55
+ ) => JSX.Element
50
56
  export default Button
@@ -0,0 +1,81 @@
1
+ // This file is for type testing only
2
+
3
+ // only use the type
4
+ import type { default as ButtonType } from './index'
5
+ import type styledType from 'styled-components'
6
+
7
+ declare const Button: typeof ButtonType
8
+ declare const styled: typeof styledType
9
+
10
+ const Custom = ({ custom }: { custom: string }) => <>{custom}</>
11
+ const CustomGeneric = <C extends string>({ custom }: { custom: C }) => (
12
+ <>{custom}</>
13
+ )
14
+
15
+ const StyledButton = styled(Button)``
16
+ const StyledButtonAsButton = styled(Button<'button'>)``
17
+ const StyledButtonA = styled(Button<'a'>)``
18
+ const StyledButtonCustom = styled(Button<typeof Custom>)``
19
+ const StyledButtonCustomAsButton = styled(
20
+ Button<typeof Custom>
21
+ )`` as typeof Button
22
+ const StyledButtonCustomGeneric = styled(Button<typeof CustomGeneric>)``
23
+ const StyledButtonCustomGenericFoo = styled(
24
+ Button<typeof CustomGeneric<'foo'>>
25
+ )``
26
+
27
+ // for type test only
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ function Tests() {
30
+ return (
31
+ <>
32
+ {/* OK */}
33
+
34
+ <StyledButton />
35
+ <StyledButton type="button" disabled />
36
+ <StyledButtonAsButton type="button" disabled />
37
+ <StyledButtonA component="a" href="#" />
38
+ <StyledButtonCustom component={Custom} custom="" />
39
+ <StyledButtonCustomAsButton<'a'> component="a" href="#" />
40
+ <StyledButtonCustomAsButton<typeof CustomGeneric<'bar'>>
41
+ component={CustomGeneric}
42
+ custom="bar"
43
+ />
44
+ <StyledButtonCustomAsButton component="a" href="#" />
45
+ <StyledButtonCustomGeneric component={CustomGeneric} custom="" />
46
+ <StyledButtonCustomGenericFoo component={CustomGeneric} custom="foo" />
47
+ <StyledButtonCustomGenericFoo
48
+ component={CustomGeneric<'foo'>}
49
+ custom="foo"
50
+ />
51
+
52
+ {/* NG */}
53
+
54
+ {/* @ts-expect-error Property 'href' does not exist on type */}
55
+ <StyledButton href="" />
56
+ {/* @ts-expect-error Property 'href' does not exist on type */}
57
+ <StyledButtonAsButton href="" />
58
+ {/* @ts-expect-error Property 'component' is missing */}
59
+ <StyledButtonA href="#" />
60
+ {/* @ts-expect-error Property 'disabled' does not exist on type */}
61
+ <StyledButtonA disabled />
62
+ {/* @ts-expect-error Type '"button"' is not assignable to type '"a"' */}
63
+ <StyledButtonA component="button" href="" />
64
+ {/* @ts-expect-error Property 'component' is missing */}
65
+ <StyledButtonCustom custom="" />
66
+ {/* @ts-expect-error Type 'string' is not assignable */}
67
+ <StyledButtonCustom component="a" custom="" />
68
+ {/* @ts-expect-error Property 'custom' does not exist on type */}
69
+ <StyledButtonCustomAsButton custom="" />
70
+ {/* @ts-expect-error Type 'href' is not assignable */}
71
+ <StyledButtonCustomAsButton<'button'> href="#" />
72
+ <StyledButtonCustomGenericFoo
73
+ /* @ts-expect-error Type '"foo"' is not assignable to type '"bar"' */
74
+ component={CustomGeneric<'bar'>}
75
+ custom="foo"
76
+ />
77
+ {/* @ts-expect-error '""' is not assignable to type '"foo"' */}
78
+ <StyledButtonCustomGenericFoo custom="" />
79
+ </>
80
+ )
81
+ }