@charcoal-ui/react 2.2.1 → 2.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/styled.d.ts CHANGED
@@ -61,8 +61,8 @@ export declare const theme: (spec: (o: Record<string, unknown> & Readonly<{
61
61
  }> & {
62
62
  readonly typography: (size: keyof import("@charcoal-ui/theme").Typography) => import("@charcoal-ui/styled").Modified<import("@charcoal-ui/styled").Internal, "bold" | "monospace" | "preserveHalfLeading">;
63
63
  } & {
64
- readonly margin: import("@charcoal-ui/styled").ModifiedArgumented<import("@charcoal-ui/styled").Internal, "horizontal" | "vertical" | "all" | "left" | "right" | "top" | "bottom", [0 | "auto" | 4 | 8 | 16 | 24 | 40 | 64 | 104 | 168 | 272 | 440]>;
65
- readonly padding: import("@charcoal-ui/styled").ModifiedArgumented<import("@charcoal-ui/styled").Internal, "horizontal" | "vertical" | "all" | "left" | "right" | "top" | "bottom", [0 | "auto" | 4 | 8 | 16 | 24 | 40 | 64 | 104 | 168 | 272 | 440]>;
64
+ readonly margin: import("@charcoal-ui/styled").ModifiedArgumented<import("@charcoal-ui/styled").Internal, "horizontal" | "vertical" | "all" | "bottom" | "left" | "right" | "top", [0 | "auto" | 4 | 8 | 16 | 24 | 40 | 64 | 104 | 168 | 272 | 440]>;
65
+ readonly padding: import("@charcoal-ui/styled").ModifiedArgumented<import("@charcoal-ui/styled").Internal, "horizontal" | "vertical" | "all" | "bottom" | "left" | "right" | "top", [0 | "auto" | 4 | 8 | 16 | 24 | 40 | 64 | 104 | 168 | 272 | 440]>;
66
66
  } & {
67
67
  readonly width: Readonly<{
68
68
  px: (size: 0 | "auto" | 4 | 8 | 16 | 24 | 40 | 64 | 104 | 168 | 272 | 440) => import("@charcoal-ui/styled").Internal;
@@ -80,7 +80,7 @@ export declare const theme: (spec: (o: Record<string, unknown> & Readonly<{
80
80
  readonly disabled: import("@charcoal-ui/styled").Modified<import("@charcoal-ui/styled").Internal, never>;
81
81
  } & Readonly<{
82
82
  border: {
83
- readonly default: import("@charcoal-ui/styled").Modified<import("@charcoal-ui/styled").Internal, "left" | "right" | "top" | "bottom">;
83
+ readonly default: import("@charcoal-ui/styled").Modified<import("@charcoal-ui/styled").Internal, "bottom" | "left" | "right" | "top">;
84
84
  };
85
85
  }> & Readonly<{
86
86
  borderRadius: (radius: "none" | 4 | 8 | 16 | 24 | "oval") => import("@charcoal-ui/styled").Internal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/react",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,20 +50,22 @@
50
50
  "typescript": "^4.5.5"
51
51
  },
52
52
  "dependencies": {
53
- "@charcoal-ui/icons": "^2.2.1",
54
- "@charcoal-ui/styled": "^2.2.1",
55
- "@charcoal-ui/theme": "^2.2.1",
56
- "@charcoal-ui/utils": "^2.2.1",
53
+ "@charcoal-ui/icons": "^2.3.0",
54
+ "@charcoal-ui/styled": "^2.3.0",
55
+ "@charcoal-ui/theme": "^2.3.0",
56
+ "@charcoal-ui/utils": "^2.3.0",
57
57
  "@react-aria/button": "^3.6.3",
58
58
  "@react-aria/checkbox": "^3.2.3",
59
59
  "@react-aria/dialog": "^3.2.1",
60
60
  "@react-aria/focus": "^3.6.1",
61
+ "@react-aria/listbox": "^3.7.1",
61
62
  "@react-aria/overlays": "^3.12.1",
62
63
  "@react-aria/radio": "^3.4.0",
63
64
  "@react-aria/select": "^3.8.2",
64
65
  "@react-aria/ssr": "^3.3.0",
65
66
  "@react-aria/switch": "^3.1.3",
66
67
  "@react-aria/textfield": "^3.5.0",
68
+ "@react-aria/utils": "^3.14.2",
67
69
  "@react-aria/visually-hidden": "^3.2.3",
68
70
  "polished": "^4.1.4",
69
71
  "react-spring": "^9.0.0",
@@ -86,5 +88,5 @@
86
88
  "url": "https://github.com/pixiv/charcoal.git",
87
89
  "directory": "packages/react"
88
90
  },
89
- "gitHead": "3da489924e6e4c67f66c13bac76bed95366934d1"
91
+ "gitHead": "b6b0cd6117cf288735bdcf167098ace9b28e0072"
90
92
  }
@@ -18,17 +18,35 @@ type Props = {
18
18
  export const Labelled: Story<Props> = (props) => {
19
19
  return (
20
20
  <div>
21
- <Checkbox
22
- {...props}
23
- name="labelled"
24
- label="label"
25
- onBlur={action('blur')}
26
- onClick={action('click')}
27
- onChange={action('change')}
28
- onFocus={action('focus')}
29
- >
30
- 同意する
31
- </Checkbox>
21
+ <div style={{ marginBottom: '1em' }}>
22
+ <Checkbox
23
+ {...props}
24
+ name="labelled"
25
+ label="label"
26
+ onBlur={action('blur')}
27
+ onClick={action('click')}
28
+ onChange={action('change')}
29
+ onFocus={action('focus')}
30
+ >
31
+ 同意する
32
+ </Checkbox>
33
+ </div>
34
+
35
+ <div>
36
+ <Checkbox
37
+ {...props}
38
+ name="labelled"
39
+ label="label"
40
+ onBlur={action('blur')}
41
+ onClick={action('click')}
42
+ onChange={action('change')}
43
+ onFocus={action('focus')}
44
+ >
45
+ <span style={{ width: 200, display: 'block' }}>
46
+ 同意する同意する同意する同意する同意する同意する同意する同意する同意する同意する同意する同意する同意する
47
+ </span>
48
+ </Checkbox>
49
+ </div>
32
50
  </div>
33
51
  )
34
52
  }
@@ -53,10 +53,12 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
53
53
 
54
54
  return (
55
55
  <InputRoot aria-disabled={isDisabled}>
56
- <CheckboxInput type="checkbox" {...inputProps} />
57
- <CheckboxInputOverlay aria-hidden={true} checked={inputProps.checked}>
58
- <Icon name="24/Check" unsafeNonGuidelineScale={2 / 3} />
59
- </CheckboxInputOverlay>
56
+ <CheckboxRoot>
57
+ <CheckboxInput type="checkbox" {...inputProps} />
58
+ <CheckboxInputOverlay aria-hidden={true} checked={inputProps.checked}>
59
+ <Icon name="24/Check" unsafeNonGuidelineScale={2 / 3} />
60
+ </CheckboxInputOverlay>
61
+ </CheckboxRoot>
60
62
 
61
63
  {'children' in props && <InputLabel>{props.children}</InputLabel>}
62
64
  </InputRoot>
@@ -73,7 +75,7 @@ const hiddenCss = css`
73
75
  const InputRoot = styled.label`
74
76
  position: relative;
75
77
  display: flex;
76
- align-items: center;
78
+
77
79
  cursor: pointer;
78
80
  ${disabledSelector} {
79
81
  cursor: default;
@@ -83,6 +85,10 @@ const InputRoot = styled.label`
83
85
  ${theme((o) => [o.disabled])}
84
86
  `
85
87
 
88
+ const CheckboxRoot = styled.div`
89
+ position: relative;
90
+ `
91
+
86
92
  const CheckboxInput = styled.input`
87
93
  &[type='checkbox'] {
88
94
  appearance: none;
@@ -118,5 +124,9 @@ const CheckboxInputOverlay = styled.div<{ checked?: boolean }>`
118
124
  `
119
125
 
120
126
  const InputLabel = styled.div`
121
- ${theme((o) => [o.typography(14), o.font.text2])}
127
+ ${theme((o) => [o.font.text2])}
128
+
129
+ font-size: 14px;
130
+ /** checkbox の height が 20px なのでcheckbox と text が揃っているように見せるために行ボックスの高さを 20px にしている */
131
+ line-height: 20px;
122
132
  `
@@ -4,7 +4,6 @@ import {
4
4
  Overlay,
5
5
  useModalOverlay,
6
6
  useOverlay,
7
- usePreventScroll,
8
7
  } from '@react-aria/overlays'
9
8
  import styled, { css, useTheme } from 'styled-components'
10
9
  import { theme } from '../../styled'
@@ -29,8 +28,10 @@ export type ModalProps = AriaModalOverlayProps &
29
28
  isOpen: boolean
30
29
  onClose: () => void
31
30
 
32
- // NOTICE: デフォルト値を与えてはならない
33
- // (たとえば document.body をデフォルト値にすると SSR できなくなる)
31
+ /**
32
+ * https://github.com/adobe/react-spectrum/issues/3787
33
+ * Next.jsで使用する際に発生するエラーの一時的な回避策でdocument.bodyを指定する必要がある
34
+ */
34
35
  portalContainer?: HTMLElement
35
36
  }
36
37
 
@@ -39,7 +40,7 @@ const DEFAULT_Z_INDEX = 10
39
40
  /**
40
41
  * モーダルコンポーネント。
41
42
  *
42
- * @example アプリケーションルートで `<OverlayProvider>` で囲った上で利用する
43
+ * @example アプリケーションルートで `<OverlayProvider>` ないし `<CharcoalProvider>` で囲った上で利用する
43
44
  * ```tsx
44
45
  * import {
45
46
  * OverlayProvider,
@@ -78,7 +79,6 @@ export default function Modal({
78
79
  const ref = useRef<HTMLDivElement>(null)
79
80
  const { overlayProps, underlayProps } = useOverlay(props, ref)
80
81
 
81
- usePreventScroll()
82
82
  const { modalProps } = useModalOverlay(
83
83
  props,
84
84
  {
@@ -126,7 +126,7 @@ export default function Modal({
126
126
  return transition(
127
127
  ({ backgroundColor, transform }, item) =>
128
128
  item && (
129
- <Overlay>
129
+ <Overlay portalContainer={portalContainer}>
130
130
  <ModalBackground
131
131
  zIndex={zIndex}
132
132
  {...underlayProps}
@@ -4,7 +4,7 @@ import React, { useRef, useMemo } from 'react'
4
4
  import { useToggleState } from 'react-stately'
5
5
  import styled from 'styled-components'
6
6
  import { theme } from '../../styled'
7
- import { disabledSelector, px } from '@charcoal-ui/utils'
7
+ import { disabledSelector } from '@charcoal-ui/utils'
8
8
 
9
9
  export type SwitchProps = {
10
10
  name: string
@@ -59,7 +59,6 @@ const Label = styled.label`
59
59
  display: inline-grid;
60
60
  grid-template-columns: auto 1fr;
61
61
  align-items: center;
62
- gap: ${({ theme }) => px(theme.spacing[4])};
63
62
  cursor: pointer;
64
63
  outline: 0;
65
64
 
@@ -71,7 +70,11 @@ const Label = styled.label`
71
70
  `
72
71
 
73
72
  const LabelInner = styled.div`
74
- ${theme((o) => [o.typography(14), o.font.text2])}
73
+ ${theme((o) => [
74
+ o.typography(14).preserveHalfLeading,
75
+ o.font.text2,
76
+ o.margin.left(4),
77
+ ])}
75
78
  `
76
79
 
77
80
  const SwitchInput = styled.input.attrs({
@@ -91,6 +94,7 @@ const SwitchInput = styled.input.attrs({
91
94
  o.height.px(16),
92
95
  o.bg.text4.hover.press,
93
96
  o.outline.default.focus,
97
+ o.margin.all(0),
94
98
  ])}
95
99
 
96
100
  &::after {
@@ -0,0 +1,35 @@
1
+ import React from 'react'
2
+ import { ThemeProvider } from 'styled-components'
3
+ import ComponentAbstraction, { Components } from './ComponentAbstraction'
4
+ import { TokenInjector } from '@charcoal-ui/styled'
5
+ import { ThemeMap } from '@charcoal-ui/styled/src/TokenInjector'
6
+ import { CharcoalTheme } from '@charcoal-ui/theme'
7
+
8
+ import { OverlayProvider } from './OverlayProvider'
9
+ import { SSRProvider } from './SSRProvider'
10
+
11
+ export type CharcoalProviderProps = React.PropsWithChildren<{
12
+ themeMap: ThemeMap<CharcoalTheme>
13
+ defaultTheme?: CharcoalTheme
14
+ injectTokens?: boolean
15
+ components?: Partial<Components>
16
+ }>
17
+
18
+ export function CharcoalProvider({
19
+ themeMap,
20
+ defaultTheme = themeMap[':root'],
21
+ components = {},
22
+ injectTokens = true,
23
+ children,
24
+ }: CharcoalProviderProps) {
25
+ return (
26
+ <SSRProvider>
27
+ <ThemeProvider theme={defaultTheme}>
28
+ {injectTokens && <TokenInjector theme={themeMap} />}
29
+ <ComponentAbstraction components={components}>
30
+ <OverlayProvider>{children}</OverlayProvider>
31
+ </ComponentAbstraction>
32
+ </ThemeProvider>
33
+ </SSRProvider>
34
+ )
35
+ }
@@ -17,7 +17,7 @@ export const DefaultLink = React.forwardRef<HTMLAnchorElement, LinkProps>(
17
17
  }
18
18
  )
19
19
 
20
- interface Components {
20
+ export interface Components {
21
21
  Link: React.ComponentType<React.ComponentPropsWithRef<typeof DefaultLink>>
22
22
  }
23
23
 
package/src/index.ts CHANGED
@@ -5,6 +5,10 @@ export {
5
5
  } from './core/ComponentAbstraction'
6
6
  export { SSRProvider } from './core/SSRProvider'
7
7
  export { OverlayProvider } from './core/OverlayProvider'
8
+ export {
9
+ CharcoalProvider,
10
+ type CharcoalProviderProps,
11
+ } from './core/CharcoalProvider'
8
12
  export { default as Button, type ButtonProps } from './components/Button'
9
13
  export {
10
14
  default as Clickable,