@charcoal-ui/react 3.3.0-beta.0 → 3.3.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/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Checkbox/index.story.d.ts +1 -0
- package/dist/components/Checkbox/index.story.d.ts.map +1 -1
- package/dist/index.cjs.js +5 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +5 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
- package/src/components/Checkbox/index.story.tsx +3 -0
- package/src/components/Checkbox/index.tsx +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/react",
|
|
3
|
-
"version": "3.3.0
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"typescript": "^4.9.5"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@charcoal-ui/icons": "^3.3.0
|
|
55
|
-
"@charcoal-ui/styled": "^3.3.0
|
|
56
|
-
"@charcoal-ui/theme": "^3.3.0
|
|
57
|
-
"@charcoal-ui/utils": "^3.3.0
|
|
54
|
+
"@charcoal-ui/icons": "^3.3.0",
|
|
55
|
+
"@charcoal-ui/styled": "^3.3.0",
|
|
56
|
+
"@charcoal-ui/theme": "^3.3.0",
|
|
57
|
+
"@charcoal-ui/utils": "^3.3.0",
|
|
58
58
|
"@react-aria/button": "^3.7.0",
|
|
59
59
|
"@react-aria/checkbox": "^3.8.0",
|
|
60
60
|
"@react-aria/dialog": "^3.5.0",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"url": "https://github.com/pixiv/charcoal.git",
|
|
91
91
|
"directory": "packages/react"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "60cfc06dc31206cb629f762f263be3fe46a13808"
|
|
94
94
|
}
|
|
@@ -13,6 +13,7 @@ type Props = {
|
|
|
13
13
|
disabled: boolean
|
|
14
14
|
readonly: boolean
|
|
15
15
|
className?: string
|
|
16
|
+
invalid: boolean
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export const Labelled: Story<Props> = (props) => {
|
|
@@ -56,6 +57,7 @@ Labelled.args = {
|
|
|
56
57
|
defaultChecked: false,
|
|
57
58
|
disabled: false,
|
|
58
59
|
readonly: false,
|
|
60
|
+
invalid: false,
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export const Unlabelled: Story<Props> = (props) => {
|
|
@@ -79,4 +81,5 @@ Unlabelled.args = {
|
|
|
79
81
|
defaultChecked: false,
|
|
80
82
|
disabled: false,
|
|
81
83
|
readonly: false,
|
|
84
|
+
invalid: false,
|
|
82
85
|
}
|
|
@@ -27,6 +27,7 @@ export type CheckboxProps = CheckboxLabelProps & {
|
|
|
27
27
|
readonly defaultChecked?: boolean
|
|
28
28
|
readonly disabled?: boolean
|
|
29
29
|
readonly readonly?: boolean
|
|
30
|
+
readonly invalid?: boolean
|
|
30
31
|
|
|
31
32
|
readonly onClick?: () => void
|
|
32
33
|
readonly onChange?: (isSelected: boolean) => void
|
|
@@ -35,17 +36,18 @@ export type CheckboxProps = CheckboxLabelProps & {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
38
|
-
function CheckboxInner(props, ref) {
|
|
39
|
+
function CheckboxInner({ invalid = false, ...props }, ref) {
|
|
39
40
|
const ariaCheckboxProps = useMemo<AriaCheckboxProps>(
|
|
40
41
|
() => ({
|
|
41
42
|
...props,
|
|
42
43
|
isSelected: props.checked,
|
|
43
44
|
defaultSelected: props.defaultChecked,
|
|
45
|
+
validationState: invalid ? 'invalid' : 'valid',
|
|
44
46
|
// children がいない場合は aria-label をつけないといけない
|
|
45
47
|
'aria-label': 'children' in props ? undefined : props.label,
|
|
46
48
|
isDisabled: props.disabled,
|
|
47
49
|
}),
|
|
48
|
-
[props]
|
|
50
|
+
[invalid, props]
|
|
49
51
|
)
|
|
50
52
|
const state = useToggleState(ariaCheckboxProps)
|
|
51
53
|
const objectRef = useObjectRef(ref)
|
|
@@ -56,7 +58,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
56
58
|
return (
|
|
57
59
|
<InputRoot aria-disabled={isDisabled} className={props.className}>
|
|
58
60
|
<CheckboxRoot>
|
|
59
|
-
<CheckboxInput type="checkbox" {...inputProps} />
|
|
61
|
+
<CheckboxInput type="checkbox" {...inputProps} invalid={invalid} />
|
|
60
62
|
<CheckboxInputOverlay aria-hidden={true} checked={inputProps.checked}>
|
|
61
63
|
<Icon name="24/Check" unsafeNonGuidelineScale={2 / 3} />
|
|
62
64
|
</CheckboxInputOverlay>
|
|
@@ -91,7 +93,7 @@ const CheckboxRoot = styled.div`
|
|
|
91
93
|
position: relative;
|
|
92
94
|
`
|
|
93
95
|
|
|
94
|
-
const CheckboxInput = styled.input
|
|
96
|
+
const CheckboxInput = styled.input<{ invalid: boolean }>`
|
|
95
97
|
&[type='checkbox'] {
|
|
96
98
|
appearance: none;
|
|
97
99
|
display: block;
|
|
@@ -109,6 +111,7 @@ const CheckboxInput = styled.input`
|
|
|
109
111
|
border-color: ${({ theme }) => theme.color.text4};
|
|
110
112
|
}
|
|
111
113
|
${theme((o) => [o.outline.default.focus, o.borderRadius(4)])}
|
|
114
|
+
${(p) => p.invalid && theme((o) => [o.outline.assertive])}
|
|
112
115
|
|
|
113
116
|
/* FIXME: o.outline.default.focus の transition に o.bg.brand の transition が打ち消されてしまう */
|
|
114
117
|
transition: all 0.2s !important;
|