@charcoal-ui/react 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/react",
3
- "version": "3.2.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",
@@ -19,14 +19,15 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@react-types/switch": "^3.1.2",
22
- "@storybook/addon-actions": "^6.4.17",
23
- "@storybook/addon-knobs": "^6.4.0",
24
- "@storybook/addons": "^6.4.17",
25
- "@storybook/api": "^6.4.17",
26
- "@storybook/components": "^6.4.17",
27
- "@storybook/core-events": "^6.4.17",
28
- "@storybook/react": "^6.4.17",
29
- "@storybook/theming": "^6.4.17",
22
+ "@storybook/addon-actions": "^7.4.1",
23
+ "@storybook/addon-knobs": "^7.0.2",
24
+ "@storybook/addons": "^7.4.1",
25
+ "@storybook/api": "^7.4.1",
26
+ "@storybook/components": "^7.4.1",
27
+ "@storybook/core-events": "^7.4.1",
28
+ "@storybook/react": "^7.4.1",
29
+ "@storybook/react-webpack5": "^7.4.1",
30
+ "@storybook/theming": "^7.4.1",
30
31
  "@testing-library/jest-dom": "^5.16.1",
31
32
  "@testing-library/react": "^12.1.2",
32
33
  "@testing-library/user-event": "^13.5.0",
@@ -44,15 +45,16 @@
44
45
  "react-dom": "^17.0.2",
45
46
  "react-router-dom": "^6.2.1",
46
47
  "rimraf": "^3.0.2",
48
+ "storybook": "^7.4.1",
47
49
  "styled-components": "^5.3.3",
48
50
  "tsup": "^6.5.0",
49
51
  "typescript": "^4.9.5"
50
52
  },
51
53
  "dependencies": {
52
- "@charcoal-ui/icons": "^3.2.0",
53
- "@charcoal-ui/styled": "^3.2.0",
54
- "@charcoal-ui/theme": "^3.2.0",
55
- "@charcoal-ui/utils": "^3.2.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",
56
58
  "@react-aria/button": "^3.7.0",
57
59
  "@react-aria/checkbox": "^3.8.0",
58
60
  "@react-aria/dialog": "^3.5.0",
@@ -88,5 +90,5 @@
88
90
  "url": "https://github.com/pixiv/charcoal.git",
89
91
  "directory": "packages/react"
90
92
  },
91
- "gitHead": "495dc492d64a159618461a074b2315547eeda99f"
93
+ "gitHead": "60cfc06dc31206cb629f762f263be3fe46a13808"
92
94
  }
@@ -1,12 +1,12 @@
1
1
  import 'jest-styled-components'
2
2
 
3
3
  import Button from '.'
4
- import renderder from 'react-test-renderer'
4
+ import renderer from 'react-test-renderer'
5
5
  import { ThemeProvider } from 'styled-components'
6
6
  import { light } from '@charcoal-ui/theme'
7
7
 
8
8
  export function render(children: JSX.Element) {
9
- return renderder
9
+ return renderer
10
10
  .create(<ThemeProvider theme={light}>{children}</ThemeProvider>)
11
11
  .toJSON()
12
12
  }
@@ -58,7 +58,7 @@ const StyledButton = styled(Clickable)<StyledProps>`
58
58
  ${(p) =>
59
59
  theme((o) => [
60
60
  o.font[variantToFont(p.$variant)].hover.press,
61
- o.bg[variantToBackgraund(p.$variant)].hover.press,
61
+ o.bg[variantToBackground(p.$variant)].hover.press,
62
62
  o.typography(14).bold.preserveHalfLeading,
63
63
  o.padding.horizontal(p.$size === 'M' ? 24 : 16),
64
64
  o.disabled,
@@ -70,7 +70,7 @@ const StyledButton = styled(Clickable)<StyledProps>`
70
70
  height: ${(p) => (p.$size === 'M' ? 40 : 32)}px;
71
71
  `
72
72
 
73
- function variantToBackgraund(variant: Variant) {
73
+ function variantToBackground(variant: Variant) {
74
74
  switch (variant) {
75
75
  case 'Overlay':
76
76
  return 'surface4'
@@ -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;
@@ -2,12 +2,12 @@ import { light } from '@charcoal-ui/theme'
2
2
  import 'jest-styled-components'
3
3
 
4
4
  import React from 'react'
5
- import renderder from 'react-test-renderer'
5
+ import renderer from 'react-test-renderer'
6
6
  import { ThemeProvider } from 'styled-components'
7
7
  import Checkbox from '.'
8
8
 
9
9
  export function render(children: JSX.Element) {
10
- return renderder
10
+ return renderer
11
11
  .create(<ThemeProvider theme={light}>{children}</ThemeProvider>)
12
12
  .toJSON()
13
13
  }
@@ -50,7 +50,7 @@ const LoadingSpinnerRoot = styled.div.attrs({ role: 'progressbar' })<{
50
50
  ])}
51
51
  `
52
52
 
53
- const scaleout = keyframes`
53
+ const scaleOut = keyframes`
54
54
  from {
55
55
  transform: scale(0);
56
56
  opacity: 1;
@@ -67,7 +67,7 @@ const Icon = styled.div.attrs({ role: 'presentation' })<{ once: boolean }>`
67
67
  height: 1em;
68
68
  border-radius: 1em;
69
69
  background-color: currentColor;
70
- animation: ${scaleout} 1s both ease-out;
70
+ animation: ${scaleOut} 1s both ease-out;
71
71
  animation-iteration-count: ${(p) => (p.once ? 1 : 'infinite')};
72
72
 
73
73
  &[data-reset-animation] {
@@ -3,7 +3,7 @@ import { ThemeProvider } from 'styled-components'
3
3
  import ComponentAbstraction, { Components } from './ComponentAbstraction'
4
4
  import { TokenInjector } from '@charcoal-ui/styled'
5
5
  import { ThemeMap } from '@charcoal-ui/styled/src/TokenInjector'
6
- import { CharcoalTheme } from '@charcoal-ui/theme'
6
+ import { CharcoalTheme, ThemeColor } from '@charcoal-ui/theme'
7
7
 
8
8
  import { OverlayProvider } from './OverlayProvider'
9
9
  import { SSRProvider } from './SSRProvider'
@@ -13,6 +13,7 @@ export type CharcoalProviderProps = React.PropsWithChildren<{
13
13
  defaultTheme?: CharcoalTheme
14
14
  injectTokens?: boolean
15
15
  components?: Partial<Components>
16
+ background?: keyof ThemeColor
16
17
  }>
17
18
 
18
19
  export function CharcoalProvider({
@@ -21,11 +22,14 @@ export function CharcoalProvider({
21
22
  components = {},
22
23
  injectTokens = true,
23
24
  children,
25
+ background,
24
26
  }: CharcoalProviderProps) {
25
27
  return (
26
28
  <SSRProvider>
27
29
  <ThemeProvider theme={defaultTheme}>
28
- {injectTokens && <TokenInjector theme={themeMap} />}
30
+ {injectTokens && (
31
+ <TokenInjector theme={themeMap} background={background} />
32
+ )}
29
33
  <ComponentAbstraction components={components}>
30
34
  <OverlayProvider>{children}</OverlayProvider>
31
35
  </ComponentAbstraction>