@charcoal-ui/react 4.0.0-beta.5 → 4.0.0-beta.7

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 (71) hide show
  1. package/README.md +1 -1
  2. package/dist/_lib/createDivComponent.d.ts +4 -0
  3. package/dist/_lib/createDivComponent.d.ts.map +1 -0
  4. package/dist/components/Modal/ModalPlumbing.d.ts.map +1 -1
  5. package/dist/components/Modal/index.d.ts +4 -0
  6. package/dist/components/Modal/index.d.ts.map +1 -1
  7. package/dist/components/TextArea/index.d.ts +1 -0
  8. package/dist/components/TextArea/index.d.ts.map +1 -1
  9. package/dist/components/TextField/AssistiveText/index.d.ts +5 -0
  10. package/dist/components/TextField/AssistiveText/index.d.ts.map +1 -0
  11. package/dist/components/TextField/index.d.ts +1 -3
  12. package/dist/components/TextField/index.d.ts.map +1 -1
  13. package/dist/core/SSRProvider.d.ts +3 -1
  14. package/dist/core/SSRProvider.d.ts.map +1 -1
  15. package/dist/index.cjs.js +250 -268
  16. package/dist/index.cjs.js.map +1 -1
  17. package/dist/index.css +156 -0
  18. package/dist/index.css.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.esm.js +139 -158
  22. package/dist/index.esm.js.map +1 -1
  23. package/package.json +8 -8
  24. package/src/_lib/createDivComponent.tsx +11 -0
  25. package/src/components/Button/__snapshots__/index.story.storyshot +9 -9
  26. package/src/components/Button/index.story.tsx +1 -1
  27. package/src/components/Checkbox/CheckboxInput/__snapshots__/index.story.storyshot +5 -5
  28. package/src/components/Checkbox/CheckboxInput/index.story.tsx +1 -1
  29. package/src/components/Checkbox/__snapshots__/index.story.storyshot +6 -6
  30. package/src/components/Checkbox/index.story.tsx +2 -2
  31. package/src/components/Clickable/__snapshots__/index.story.storyshot +2 -2
  32. package/src/components/Clickable/index.story.tsx +1 -1
  33. package/src/components/DropdownSelector/ListItem/__snapshots__/index.story.storyshot +1 -1
  34. package/src/components/DropdownSelector/ListItem/index.story.tsx +1 -1
  35. package/src/components/DropdownSelector/MenuList/__snapshots__/index.story.storyshot +3 -3
  36. package/src/components/DropdownSelector/MenuList/index.story.tsx +1 -1
  37. package/src/components/DropdownSelector/Popover/__snapshots__/index.story.storyshot +1 -1
  38. package/src/components/DropdownSelector/Popover/index.story.tsx +1 -1
  39. package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +22 -579
  40. package/src/components/DropdownSelector/index.story.tsx +2 -2
  41. package/src/components/DropdownSelector/index.tsx +2 -2
  42. package/src/components/Icon/__snapshots__/index.story.storyshot +1 -1
  43. package/src/components/Icon/index.story.tsx +1 -1
  44. package/src/components/IconButton/__snapshots__/index.story.storyshot +3 -3
  45. package/src/components/IconButton/index.story.tsx +1 -1
  46. package/src/components/LoadingSpinner/__snapshots__/index.story.storyshot +4 -4
  47. package/src/components/LoadingSpinner/index.story.tsx +1 -1
  48. package/src/components/Modal/ModalPlumbing.tsx +2 -11
  49. package/src/components/Modal/__snapshots__/index.story.storyshot +104 -288
  50. package/src/components/Modal/index.story.tsx +2 -2
  51. package/src/components/Modal/index.tsx +17 -5
  52. package/src/components/Radio/__snapshots__/index.story.storyshot +5 -5
  53. package/src/components/Radio/index.story.tsx +1 -1
  54. package/src/components/SegmentedControl/__snapshots__/index.story.storyshot +2 -2
  55. package/src/components/SegmentedControl/index.story.tsx +1 -1
  56. package/src/components/Switch/__snapshots__/index.story.storyshot +4 -4
  57. package/src/components/Switch/index.story.tsx +1 -1
  58. package/src/components/TagItem/__snapshots__/index.story.storyshot +8 -8
  59. package/src/components/TagItem/index.story.tsx +1 -1
  60. package/src/components/TextArea/TextArea.story.tsx +1 -1
  61. package/src/components/TextArea/__snapshots__/TextArea.story.storyshot +152 -824
  62. package/src/components/TextArea/index.css +78 -0
  63. package/src/components/TextArea/index.tsx +26 -96
  64. package/src/components/TextField/AssistiveText/index.css +10 -0
  65. package/src/components/TextField/AssistiveText/index.tsx +6 -0
  66. package/src/components/TextField/TextField.story.tsx +1 -1
  67. package/src/components/TextField/__snapshots__/TextField.story.storyshot +122 -1072
  68. package/src/components/TextField/index.css +87 -0
  69. package/src/components/TextField/index.tsx +24 -117
  70. package/src/core/SSRProvider.tsx +12 -1
  71. package/src/index.ts +5 -1
@@ -0,0 +1,78 @@
1
+ .charcoal-text-area-root {
2
+ display: grid;
3
+ grid-template-columns: 1fr;
4
+ grid-gap: 4px;
5
+ }
6
+
7
+ .charcoal-text-area-root[aria-disabled='true'] {
8
+ opacity: 0.32;
9
+ }
10
+
11
+ .charcoal-text-area-container {
12
+ position: relative;
13
+ overflow: hidden;
14
+
15
+ color: var(--charcoal-text2);
16
+ background-color: var(--charcoal-surface3);
17
+ border-radius: 4px;
18
+ transition: 0.2s background-color, 0.2s box-shadow;
19
+ height: calc(22px * var(--charcoal-text-area-rows) + 18px);
20
+ }
21
+
22
+ .charcoal-text-area-container[aria-invalid='true'] {
23
+ box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
24
+ }
25
+
26
+ .charcoal-text-area-container:focus-within {
27
+ outline: none;
28
+ box-shadow: 0 0 0 4px rgba(0, 150, 250, 0.32);
29
+ }
30
+
31
+ .charcoal-text-area-container:not(aria-disabled='true'):hover {
32
+ background-color: var(--charcoal-surface3-hover);
33
+ }
34
+
35
+ .charcoal-text-area-container[aria-invalid='true']:focus-within {
36
+ box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
37
+ }
38
+
39
+ .charcoal-text-area-textarea {
40
+ border: none;
41
+ outline: none;
42
+ resize: none;
43
+ font-family: inherit;
44
+ color: inherit;
45
+ box-sizing: border-box;
46
+
47
+ /* Prevent zooming for iOS Safari */
48
+ transform-origin: top left;
49
+ transform: scale(0.875);
50
+ width: calc(100% / 0.875);
51
+ font-size: calc(14px / 0.875);
52
+ line-height: calc(22px / 0.875);
53
+ padding: calc(9px / 0.875) calc(8px / 0.875);
54
+ height: calc(22px / 0.875 * var(--charcoal-text-area-rows) + 20px);
55
+
56
+ /* Display box-shadow for iOS Safari */
57
+ appearance: none;
58
+
59
+ background: none;
60
+ }
61
+ .charcoal-text-area-textarea[data-no-bottom-padding='true'] {
62
+ padding: calc(9px / 0.875) calc(8px / 0.875) 0;
63
+ height: calc(22px / 0.875 * (var(--charcoal-text-area-rows) - 1) + 9px);
64
+ }
65
+
66
+ .charcoal-text-area-textarea::placeholder {
67
+ color: var(--charcoal-text3);
68
+ }
69
+
70
+ .charcoal-text-area-counter {
71
+ position: absolute;
72
+ bottom: 9px;
73
+ right: 8px;
74
+
75
+ line-height: 22px;
76
+ font-size: 14px;
77
+ color: var(--charcoal-text3);
78
+ }
@@ -1,11 +1,13 @@
1
+ import './index.css'
2
+
1
3
  import { useVisuallyHidden } from '@react-aria/visually-hidden'
2
4
  import { forwardRef, useCallback, useEffect, useRef, useState } from 'react'
3
- import styled, { css } from 'styled-components'
4
5
  import FieldLabel from '../FieldLabel'
5
6
  import { countCodePointsInString, mergeRefs } from '../../_lib'
6
- import { AssistiveText } from '../TextField'
7
7
  import { useFocusWithClick } from '../TextField/useFocusWithClick'
8
8
  import { useId } from '@react-aria/utils'
9
+ import { AssistiveText } from '../TextField/AssistiveText'
10
+ import { useClassNames } from '../../_lib/useClassNames'
9
11
 
10
12
  export type TextAreaProps = {
11
13
  value?: string
@@ -42,6 +44,7 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
42
44
  maxLength,
43
45
  autoHeight = false,
44
46
  rows: initialRows = 4,
47
+ invalid,
45
48
  getCount = countCodePointsInString,
46
49
  ...props
47
50
  },
@@ -49,7 +52,6 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
49
52
  ) {
50
53
  const { visuallyHiddenProps } = useVisuallyHidden()
51
54
  const textareaRef = useRef<HTMLTextAreaElement>(null)
52
- const textAreaRef = useRef<HTMLTextAreaElement>(null)
53
55
  const [count, setCount] = useState(getCount(value ?? ''))
54
56
  const [rows, setRows] = useState(initialRows)
55
57
 
@@ -92,17 +94,19 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
92
94
 
93
95
  const containerRef = useRef(null)
94
96
 
95
- useFocusWithClick(containerRef, textAreaRef)
97
+ useFocusWithClick(containerRef, textareaRef)
96
98
 
97
99
  const textAreaId = useId(props.id)
98
100
  const describedbyId = useId()
99
101
  const labelledbyId = useId()
100
102
 
103
+ const classNames = useClassNames('charcoal-text-area-root', className)
104
+
101
105
  const showAssistiveText =
102
106
  assistiveText != null && assistiveText.length !== 0
103
107
 
104
108
  return (
105
- <TextFieldRoot className={className} isDisabled={disabled}>
109
+ <div className={classNames} aria-disabled={disabled}>
106
110
  <FieldLabel
107
111
  htmlFor={textAreaId}
108
112
  id={labelledbyId}
@@ -112,118 +116,44 @@ const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
112
116
  subLabel={subLabel}
113
117
  {...(!showLabel ? visuallyHiddenProps : {})}
114
118
  />
115
- <StyledTextareaContainer
119
+ <div
120
+ className="charcoal-text-area-container"
116
121
  aria-disabled={disabled === true ? 'true' : undefined}
117
- invalid={props.invalid === true}
122
+ aria-invalid={invalid === true}
118
123
  ref={containerRef}
119
- rows={showCount ? rows + 1 : rows}
124
+ style={{
125
+ '--charcoal-text-area-rows': `${showCount ? rows + 1 : rows}`,
126
+ }}
120
127
  >
121
- <StyledTextarea
128
+ <textarea
129
+ className="charcoal-text-area-textarea"
122
130
  aria-describedby={showAssistiveText ? describedbyId : undefined}
123
- aria-invalid={props.invalid}
131
+ aria-invalid={invalid}
124
132
  aria-labelledby={labelledbyId}
125
133
  id={textAreaId}
126
134
  maxLength={maxLength}
127
- noBottomPadding={showCount}
135
+ data-no-bottom-padding={showCount}
128
136
  onChange={handleChange}
129
- ref={mergeRefs(forwardRef, textAreaRef)}
137
+ ref={mergeRefs(forwardRef, textareaRef)}
130
138
  rows={rows}
131
139
  value={value}
140
+ disabled={disabled}
132
141
  {...props}
133
142
  />
134
143
  {showCount && (
135
- <MultiLineCounter>
144
+ <span className="charcoal-text-area-counter">
136
145
  {maxLength !== undefined ? `${count}/${maxLength}` : count}
137
- </MultiLineCounter>
146
+ </span>
138
147
  )}
139
- </StyledTextareaContainer>
148
+ </div>
140
149
  {showAssistiveText && (
141
- <AssistiveText invalid={props.invalid === true} id={describedbyId}>
150
+ <AssistiveText data-invalid={invalid === true} id={describedbyId}>
142
151
  {assistiveText}
143
152
  </AssistiveText>
144
153
  )}
145
- </TextFieldRoot>
154
+ </div>
146
155
  )
147
156
  }
148
157
  )
149
158
 
150
159
  export default TextArea
151
-
152
- const TextFieldRoot = styled.div<{ isDisabled: boolean }>`
153
- display: grid;
154
- grid-template-columns: 1fr;
155
- grid-gap: 4px;
156
-
157
- ${(p) => p.isDisabled && { opacity: p.theme.elementEffect.disabled.opacity }}
158
- `
159
-
160
- const StyledTextareaContainer = styled.div<{ rows: number; invalid: boolean }>`
161
- position: relative;
162
- overflow: hidden;
163
-
164
- color: var(--charcoal-text2);
165
- background-color: var(--charcoal-surface3);
166
- border-radius: 4px;
167
- transition: 0.2s background-color, 0.2s box-shadow;
168
-
169
- ${({ rows }) => css`
170
- height: calc(22px * ${rows} + 18px);
171
- `};
172
-
173
- :not([aria-disabled]):hover,
174
- [aria-disabled='false']:hover {
175
- background-color: var(--charcoal-surface3-hover);
176
- }
177
- :focus-within {
178
- outline: none;
179
- box-shadow: 0 0 0 4px
180
- ${(p) => (p.invalid ? `rgba(255,43,0,0.32)` : `rgba(0, 150, 250, 0.32);`)};
181
- }
182
-
183
- ${(p) =>
184
- p.invalid &&
185
- css`
186
- box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
187
- `}
188
- `
189
-
190
- const StyledTextarea = styled.textarea<{ noBottomPadding: boolean }>`
191
- border: none;
192
- outline: none;
193
- resize: none;
194
- font-family: inherit;
195
- color: inherit;
196
- box-sizing: border-box;
197
-
198
- /* Prevent zooming for iOS Safari */
199
- transform-origin: top left;
200
- transform: scale(0.875);
201
- width: calc(100% / 0.875);
202
- font-size: calc(14px / 0.875);
203
- line-height: calc(22px / 0.875);
204
- padding: calc(9px / 0.875) calc(8px / 0.875)
205
- ${(p) => (p.noBottomPadding ? 0 : '')};
206
-
207
- ${({ rows = 1, noBottomPadding }) => css`
208
- height: calc(22px / 0.875 * ${rows} + ${noBottomPadding ? 9 : 20}px);
209
- `};
210
-
211
- /* Display box-shadow for iOS Safari */
212
- appearance: none;
213
-
214
- background: none;
215
-
216
- &::placeholder {
217
- color: var(--charcoal-text3);
218
- }
219
- `
220
-
221
- const MultiLineCounter = styled.span`
222
- position: absolute;
223
- bottom: 9px;
224
- right: 8px;
225
-
226
- line-height: 22px;
227
- font-size: 14px;
228
- color: var(--charcoal-text3);
229
- `
@@ -0,0 +1,10 @@
1
+ .charcoal-text-field-assistive-text {
2
+ font-size: 14px;
3
+ line-height: 22px;
4
+ margin: 0;
5
+ color: var(--charcoal-text2);
6
+ }
7
+
8
+ .charcoal-text-field-assistive-text[data-invalid='true'] {
9
+ color: var(--charcoal-assertive);
10
+ }
@@ -0,0 +1,6 @@
1
+ import { createDivComponent } from '../../../_lib/createDivComponent'
2
+ import './index.css'
3
+
4
+ export const AssistiveText = createDivComponent(
5
+ 'charcoal-text-field-assistive-text'
6
+ )
@@ -5,7 +5,7 @@ import { useState } from 'react'
5
5
  import { Meta, StoryObj } from '@storybook/react'
6
6
 
7
7
  export default {
8
- title: 'TextField',
8
+ title: 'react/TextField',
9
9
  component: TextField,
10
10
  parameters: {
11
11
  layout: 'centered',