@charcoal-ui/react 3.4.0 → 3.6.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.
Files changed (77) hide show
  1. package/dist/components/Button/index.d.ts.map +1 -1
  2. package/dist/components/Checkbox/index.d.ts.map +1 -1
  3. package/dist/components/Checkbox/index.story.d.ts +1 -0
  4. package/dist/components/Checkbox/index.story.d.ts.map +1 -1
  5. package/dist/components/DropdownSelector/DropdownMenuItem.d.ts.map +1 -1
  6. package/dist/components/DropdownSelector/ListItem/index.d.ts.map +1 -1
  7. package/dist/components/DropdownSelector/Popover/index.d.ts.map +1 -1
  8. package/dist/components/DropdownSelector/index.d.ts.map +1 -1
  9. package/dist/components/FieldLabel/index.d.ts.map +1 -1
  10. package/dist/components/IconButton/index.d.ts.map +1 -1
  11. package/dist/components/LoadingSpinner/index.d.ts.map +1 -1
  12. package/dist/components/Modal/ModalPlumbing.d.ts.map +1 -1
  13. package/dist/components/Modal/index.d.ts.map +1 -1
  14. package/dist/components/Modal/index.story.d.ts +1 -0
  15. package/dist/components/Modal/index.story.d.ts.map +1 -1
  16. package/dist/components/MultiSelect/index.d.ts.map +1 -1
  17. package/dist/components/MultiSelect/index.story.d.ts +2 -0
  18. package/dist/components/MultiSelect/index.story.d.ts.map +1 -1
  19. package/dist/components/Radio/index.d.ts.map +1 -1
  20. package/dist/components/SegmentedControl/index.d.ts.map +1 -1
  21. package/dist/components/Switch/index.d.ts.map +1 -1
  22. package/dist/components/TagItem/index.d.ts.map +1 -1
  23. package/dist/components/TextArea/index.d.ts.map +1 -1
  24. package/dist/components/TextField/TextField.story.d.ts.map +1 -1
  25. package/dist/components/TextField/index.d.ts +4 -0
  26. package/dist/components/TextField/index.d.ts.map +1 -1
  27. package/dist/components/TextField/useFocusWithClick.d.ts +3 -0
  28. package/dist/components/TextField/useFocusWithClick.d.ts.map +1 -0
  29. package/dist/index.cjs.js +935 -494
  30. package/dist/index.cjs.js.map +1 -1
  31. package/dist/index.esm.js +863 -422
  32. package/dist/index.esm.js.map +1 -1
  33. package/dist/styled.d.ts +4 -4
  34. package/package.json +9 -9
  35. package/src/components/Button/__snapshots__/index.story.storyshot +312 -592
  36. package/src/components/Button/index.tsx +50 -14
  37. package/src/components/Checkbox/__snapshots__/index.story.storyshot +209 -40
  38. package/src/components/Checkbox/__snapshots__/snapshot.test.tsx.snap +410 -80
  39. package/src/components/Checkbox/index.story.tsx +24 -0
  40. package/src/components/Checkbox/index.tsx +47 -17
  41. package/src/components/Clickable/__snapshots__/index.story.storyshot +4 -0
  42. package/src/components/Clickable/index.tsx +1 -0
  43. package/src/components/DropdownSelector/DropdownMenuItem.tsx +19 -3
  44. package/src/components/DropdownSelector/ListItem/__snapshots__/index.story.storyshot +3 -10
  45. package/src/components/DropdownSelector/ListItem/index.tsx +6 -4
  46. package/src/components/DropdownSelector/MenuItemGroup/index.tsx +1 -1
  47. package/src/components/DropdownSelector/MenuList/__snapshots__/index.story.storyshot +4 -13
  48. package/src/components/DropdownSelector/Popover/__snapshots__/index.story.storyshot +20 -37
  49. package/src/components/DropdownSelector/Popover/index.tsx +5 -8
  50. package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +60 -191
  51. package/src/components/DropdownSelector/index.tsx +70 -20
  52. package/src/components/FieldLabel/index.tsx +77 -12
  53. package/src/components/IconButton/__snapshots__/index.story.storyshot +30 -54
  54. package/src/components/IconButton/index.tsx +51 -26
  55. package/src/components/LoadingSpinner/index.tsx +3 -6
  56. package/src/components/Modal/Dialog/index.tsx +1 -1
  57. package/src/components/Modal/ModalPlumbing.tsx +26 -5
  58. package/src/components/Modal/__snapshots__/index.story.storyshot +2454 -108
  59. package/src/components/Modal/index.story.tsx +27 -0
  60. package/src/components/Modal/index.tsx +19 -4
  61. package/src/components/MultiSelect/__snapshots__/index.story.storyshot +528 -25
  62. package/src/components/MultiSelect/index.story.tsx +60 -0
  63. package/src/components/MultiSelect/index.tsx +82 -22
  64. package/src/components/Radio/__snapshots__/index.story.storyshot +32 -49
  65. package/src/components/Radio/index.tsx +71 -23
  66. package/src/components/SegmentedControl/__snapshots__/index.story.storyshot +18 -19
  67. package/src/components/SegmentedControl/index.tsx +35 -15
  68. package/src/components/Switch/__snapshots__/index.story.storyshot +6 -18
  69. package/src/components/Switch/index.tsx +10 -15
  70. package/src/components/TagItem/__snapshots__/index.story.storyshot +39 -158
  71. package/src/components/TagItem/index.tsx +84 -19
  72. package/src/components/TextArea/__snapshots__/TextArea.story.storyshot +126 -321
  73. package/src/components/TextArea/index.tsx +38 -43
  74. package/src/components/TextField/TextField.story.tsx +35 -19
  75. package/src/components/TextField/__snapshots__/TextField.story.storyshot +309 -563
  76. package/src/components/TextField/index.tsx +85 -84
  77. package/src/components/TextField/useFocusWithClick.tsx +22 -0
@@ -2,10 +2,11 @@ import { useTextField } from '@react-aria/textfield'
2
2
  import { useVisuallyHidden } from '@react-aria/visually-hidden'
3
3
  import { forwardRef, useCallback, useEffect, useRef, useState } from 'react'
4
4
  import styled, { css } from 'styled-components'
5
- import FieldLabel, { FieldLabelProps } from '../FieldLabel'
5
+ import { FieldLabelProps } from '../FieldLabel'
6
6
  import { countCodePointsInString, mergeRefs } from '../../_lib'
7
7
  import { ReactAreaUseTextFieldCompat } from '../../_lib/compat'
8
- import { theme } from '../../styled'
8
+ import { AssistiveText, TextFieldLabel } from '../TextField'
9
+ import { useFocusWithClick } from '../TextField/useFocusWithClick'
9
10
 
10
11
  type DOMProps = Omit<
11
12
  React.TextareaHTMLAttributes<HTMLTextAreaElement>,
@@ -115,6 +116,10 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
115
116
  }
116
117
  }, [autoHeight, syncHeight])
117
118
 
119
+ const containerRef = useRef(null)
120
+
121
+ useFocusWithClick(containerRef, ariaRef)
122
+
118
123
  return (
119
124
  <TextFieldRoot className={className} isDisabled={disabled}>
120
125
  <TextFieldLabel
@@ -126,8 +131,10 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
126
131
  {...(!showLabel ? visuallyHiddenProps : {})}
127
132
  />
128
133
  <StyledTextareaContainer
134
+ ref={containerRef}
129
135
  invalid={invalid}
130
136
  rows={showCount ? rows + 1 : rows}
137
+ aria-disabled={disabled === true ? 'true' : undefined}
131
138
  >
132
139
  <StyledTextarea
133
140
  ref={mergeRefs(textareaRef, forwardRef, ariaRef)}
@@ -163,32 +170,34 @@ const TextFieldRoot = styled.div<{ isDisabled: boolean }>`
163
170
  ${(p) => p.isDisabled && { opacity: p.theme.elementEffect.disabled.opacity }}
164
171
  `
165
172
 
166
- const TextFieldLabel = styled(FieldLabel)`
167
- ${theme((o) => o.margin.bottom(8))}
168
- `
169
-
170
173
  const StyledTextareaContainer = styled.div<{ rows: number; invalid: boolean }>`
171
174
  position: relative;
172
175
  overflow: hidden;
173
- padding: 0 8px;
174
176
 
175
- ${(p) =>
176
- theme((o) => [
177
- o.bg.surface3.hover,
178
- o.outline.default.focus,
179
- p.invalid && o.outline.assertive,
180
- o.font.text2,
181
- o.borderRadius(4),
182
- ])}
183
-
184
- &:focus-within {
185
- ${(p) =>
186
- theme((o) => (p.invalid ? o.outline.assertive : o.outline.default))}
187
- }
177
+ color: var(--charcoal-text2);
178
+ background-color: var(--charcoal-surface3);
179
+ border-radius: 4px;
180
+ transition: 0.2s background-color, 0.2s box-shadow;
188
181
 
189
182
  ${({ rows }) => css`
190
183
  height: calc(22px * ${rows} + 18px);
191
184
  `};
185
+
186
+ :not([aria-disabled]):hover,
187
+ [aria-disabled='false']:hover {
188
+ background-color: var(--charcoal-surface3-hover);
189
+ }
190
+ :focus-within {
191
+ outline: none;
192
+ box-shadow: 0 0 0 4px
193
+ ${(p) => (p.invalid ? `rgba(255,43,0,0.32)` : `rgba(0, 150, 250, 0.32);`)};
194
+ }
195
+
196
+ ${(p) =>
197
+ p.invalid &&
198
+ css`
199
+ box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
200
+ `}
192
201
  `
193
202
 
194
203
  const StyledTextarea = styled.textarea<{ noBottomPadding: boolean }>`
@@ -197,6 +206,7 @@ const StyledTextarea = styled.textarea<{ noBottomPadding: boolean }>`
197
206
  resize: none;
198
207
  font-family: inherit;
199
208
  color: inherit;
209
+ box-sizing: border-box;
200
210
 
201
211
  /* Prevent zooming for iOS Safari */
202
212
  transform-origin: top left;
@@ -204,10 +214,11 @@ const StyledTextarea = styled.textarea<{ noBottomPadding: boolean }>`
204
214
  width: calc(100% / 0.875);
205
215
  font-size: calc(14px / 0.875);
206
216
  line-height: calc(22px / 0.875);
207
- padding: calc(9px / 0.875) 0 ${(p) => (p.noBottomPadding ? 0 : '')};
217
+ padding: calc(9px / 0.875) calc(8px / 0.875)
218
+ ${(p) => (p.noBottomPadding ? 0 : '')};
208
219
 
209
- ${({ rows = 1 }) => css`
210
- height: calc(22px / 0.875 * ${rows});
220
+ ${({ rows = 1, noBottomPadding }) => css`
221
+ height: calc(22px / 0.875 * ${rows} + ${noBottomPadding ? 9 : 20}px);
211
222
  `};
212
223
 
213
224
  /* Display box-shadow for iOS Safari */
@@ -216,16 +227,8 @@ const StyledTextarea = styled.textarea<{ noBottomPadding: boolean }>`
216
227
  background: none;
217
228
 
218
229
  &::placeholder {
219
- ${theme((o) => o.font.text3)}
220
- }
221
-
222
- /* Hide scrollbar for Chrome, Safari and Opera */
223
- &::-webkit-scrollbar {
224
- display: none;
230
+ color: var(--charcoal-text3);
225
231
  }
226
- /* Hide scrollbar for IE, Edge and Firefox */
227
- -ms-overflow-style: none; /* IE and Edge */
228
- scrollbar-width: none; /* Firefox */
229
232
  `
230
233
 
231
234
  const MultiLineCounter = styled.span`
@@ -233,15 +236,7 @@ const MultiLineCounter = styled.span`
233
236
  bottom: 9px;
234
237
  right: 8px;
235
238
 
236
- ${theme((o) => [o.typography(14).preserveHalfLeading, o.font.text3])}
237
- `
238
-
239
- const AssistiveText = styled.p<{ invalid: boolean }>`
240
- ${(p) =>
241
- theme((o) => [
242
- o.typography(14),
243
- o.margin.top(8),
244
- o.margin.bottom(0),
245
- o.font[p.invalid ? 'assertive' : 'text1'],
246
- ])}
239
+ line-height: 22px;
240
+ font-size: 14px;
241
+ color: var(--charcoal-text3);
247
242
  `
@@ -1,10 +1,10 @@
1
- import { action } from '@storybook/addon-actions'
2
1
  import styled from 'styled-components'
3
2
  import { Story } from '../../_lib/compat'
4
3
  import Clickable from '../Clickable'
5
4
  import TextField, { TextFieldProps } from '.'
6
5
  import { px } from '@charcoal-ui/utils'
7
6
  import IconButton from '../IconButton'
7
+ import { useCallback, useState } from 'react'
8
8
 
9
9
  export default {
10
10
  title: 'TextField',
@@ -30,9 +30,7 @@ const Template: Story<Partial<TextFieldProps>> = (args) => (
30
30
  <TextField
31
31
  label="Label"
32
32
  requiredText="*必須"
33
- subLabel={
34
- <Clickable onClick={action('label-click')}>Text Link</Clickable>
35
- }
33
+ subLabel={<Clickable>Text Link</Clickable>}
36
34
  placeholder="TextField"
37
35
  {...args}
38
36
  />
@@ -64,22 +62,40 @@ HasAffix.args = {
64
62
  suffix: '.png',
65
63
  }
66
64
 
67
- export const PrefixIcon: Story<Partial<TextFieldProps>> = (args) => (
68
- <TextField
69
- label="Label"
70
- placeholder="Icon prefix"
71
- prefix={
72
- <PrefixIconWrap>
73
- <pixiv-icon name="16/Search" />
74
- </PrefixIconWrap>
75
- }
76
- suffix={<IconButton variant="Overlay" icon={'16/Remove'} size="XS" />}
77
- {...args}
78
- />
79
- )
65
+ export const PrefixIcon: Story<Partial<TextFieldProps>> = (args) => {
66
+ const [value, setValue] = useState('')
67
+ const handleChange = useCallback((value: string) => {
68
+ setValue(value)
69
+ }, [])
70
+ const handleClear = useCallback(() => {
71
+ setValue('')
72
+ }, [])
73
+ return (
74
+ <TextField
75
+ {...args}
76
+ label="Label"
77
+ placeholder="作品を検索"
78
+ value={value}
79
+ onChange={handleChange}
80
+ prefix={
81
+ <PrefixIconWrap>
82
+ <pixiv-icon name="16/Search" />
83
+ </PrefixIconWrap>
84
+ }
85
+ suffix={
86
+ <IconButton
87
+ variant="Overlay"
88
+ icon={'16/Remove'}
89
+ size="XS"
90
+ onClick={handleClear}
91
+ />
92
+ }
93
+ />
94
+ )
95
+ }
80
96
 
81
97
  const PrefixIconWrap = styled.div`
98
+ display: flex;
99
+ align-items: center;
82
100
  color: ${({ theme }) => theme.color.text3};
83
- margin-top: 2px;
84
- margin-right: 4px;
85
101
  `