@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,87 @@
1
+ .charcoal-text-field-root {
2
+ display: grid;
3
+ grid-template-columns: 1fr;
4
+ grid-gap: 4px;
5
+ }
6
+
7
+ .charcoal-text-field-root[aria-disabled='true'] {
8
+ opacity: 0.32;
9
+ }
10
+
11
+ .charcoal-text-field-container {
12
+ display: flex;
13
+ height: 40px;
14
+ transition: 0.2s background-color, 0.2s box-shadow;
15
+ color: var(--charcoal-text2);
16
+ background-color: var(--charcoal-surface3);
17
+ border-radius: 4px;
18
+ padding: 0 8px;
19
+ line-height: 22px;
20
+ font-size: 14px;
21
+ }
22
+
23
+ .charcoal-text-field-container[data-invalid='true'] {
24
+ box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
25
+ }
26
+
27
+ .charcoal-text-field-container:not([aria-disabled='true']):hover {
28
+ background-color: var(--charcoal-surface3-hover);
29
+ }
30
+
31
+ .charcoal-text-field-container:not([aria-disabled='true']):focus-within {
32
+ outline: none;
33
+ box-shadow: 0 0 0 4px rgba(0, 150, 250, 0.32);
34
+ }
35
+
36
+ .charcoal-text-field-container:not(
37
+ [aria-disabled='true']
38
+ )[data-invalid='true']:focus-within {
39
+ box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
40
+ }
41
+
42
+ .charcoal-text-field-prefix {
43
+ display: flex;
44
+ align-items: center;
45
+ margin-right: 4px;
46
+ }
47
+
48
+ .charcoal-text-field-suffix {
49
+ display: flex;
50
+ align-items: center;
51
+ gap: 8px;
52
+ margin-left: 4px;
53
+ }
54
+
55
+ .charcoal-text-field-input {
56
+ border: none;
57
+ box-sizing: border-box;
58
+ outline: none;
59
+ font-family: inherit;
60
+
61
+ /* Prevent zooming for iOS Safari */
62
+ transform-origin: top left;
63
+ transform: scale(0.875);
64
+ width: calc(100% / 0.875);
65
+ height: calc(100% / 0.875);
66
+ font-size: calc(14px / 0.875);
67
+ line-height: calc(22px / 0.875);
68
+ padding-left: 0;
69
+ padding-right: 0;
70
+ border-radius: calc(4px / 0.875);
71
+
72
+ /* Display box-shadow for iOS Safari */
73
+ appearance: none;
74
+ background: transparent;
75
+
76
+ color: var(--charcoal-text2);
77
+ }
78
+
79
+ .charcoal-text-field-input::placeholder {
80
+ color: var(--charcoal-text3);
81
+ }
82
+
83
+ .charcoal-text-field-line-counter {
84
+ line-height: 22px;
85
+ font-size: 14px;
86
+ color: var(--charcoal-text3);
87
+ }
@@ -1,11 +1,14 @@
1
+ import './index.css'
2
+
1
3
  import { useVisuallyHidden } from '@react-aria/visually-hidden'
2
4
  import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
3
5
  import * as React from 'react'
4
- import styled, { css } from 'styled-components'
5
6
  import FieldLabel from '../FieldLabel'
6
7
  import { countCodePointsInString } from '../../_lib'
7
8
  import { useFocusWithClick } from './useFocusWithClick'
8
9
  import { mergeRefs, useId } from '@react-aria/utils'
10
+ import { AssistiveText } from './AssistiveText'
11
+ import { useClassNames } from '../../_lib/useClassNames'
9
12
 
10
13
  export type TextFieldProps = {
11
14
  prefix?: ReactNode
@@ -45,6 +48,7 @@ const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
45
48
  subLabel,
46
49
  suffix = null,
47
50
  type = 'text',
51
+ invalid,
48
52
  value,
49
53
  getCount = countCodePointsInString,
50
54
  ...props
@@ -85,8 +89,10 @@ const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
85
89
  const showAssistiveText =
86
90
  assistiveText != null && assistiveText.length !== 0
87
91
 
92
+ const classNames = useClassNames('charcoal-text-field-root')
93
+
88
94
  return (
89
- <TextFieldRoot className={className} isDisabled={disabled}>
95
+ <div className={classNames} aria-disabled={disabled}>
90
96
  <FieldLabel
91
97
  htmlFor={inputId}
92
98
  id={labelledbyId}
@@ -96,146 +102,47 @@ const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
96
102
  subLabel={subLabel}
97
103
  {...(!showLabel ? visuallyHiddenProps : {})}
98
104
  />
99
- <StyledInputContainer
105
+ <div
106
+ className="charcoal-text-field-container"
100
107
  aria-disabled={disabled === true ? true : undefined}
101
- hasPrefix={prefix != null}
102
- hasSuffix={suffix != null || showCount}
103
- invalid={props.invalid === true}
108
+ data-invalid={invalid === true}
104
109
  ref={containerRef}
105
110
  >
106
- {prefix && <PrefixContainer>{prefix}</PrefixContainer>}
107
- <StyledInput
111
+ {prefix && <div className="charcoal-text-field-prefix">{prefix}</div>}
112
+ <input
113
+ className="charcoal-text-field-input"
108
114
  aria-describedby={showAssistiveText ? describedbyId : undefined}
109
- aria-invalid={props.invalid}
115
+ aria-invalid={invalid}
110
116
  aria-labelledby={labelledbyId}
111
117
  id={inputId}
112
- invalid={props.invalid === true}
118
+ data-invalid={invalid === true}
113
119
  maxLength={maxLength}
114
120
  onChange={handleChange}
115
- prefix={props.rdfaPredix}
121
+ disabled={disabled}
116
122
  ref={mergeRefs(forwardRef, inputRef)}
117
123
  type={type}
118
124
  value={value}
119
125
  {...props}
120
126
  />
121
127
  {(suffix || showCount) && (
122
- <SuffixContainer>
128
+ <div className="charcoal-text-field-suffix">
123
129
  {suffix}
124
130
  {showCount && (
125
- <SingleLineCounter>
131
+ <span className="charcoal-text-field-line-counter">
126
132
  {maxLength !== undefined ? `${count}/${maxLength}` : count}
127
- </SingleLineCounter>
133
+ </span>
128
134
  )}
129
- </SuffixContainer>
135
+ </div>
130
136
  )}
131
- </StyledInputContainer>
137
+ </div>
132
138
  {showAssistiveText && (
133
- <AssistiveText invalid={props.invalid === true} id={describedbyId}>
139
+ <AssistiveText data-invalid={invalid === true} id={describedbyId}>
134
140
  {assistiveText}
135
141
  </AssistiveText>
136
142
  )}
137
- </TextFieldRoot>
143
+ </div>
138
144
  )
139
145
  }
140
146
  )
141
147
 
142
148
  export default TextField
143
-
144
- const TextFieldRoot = styled.div<{ isDisabled: boolean }>`
145
- display: grid;
146
- grid-template-columns: 1fr;
147
- grid-gap: 4px;
148
-
149
- ${(p) => p.isDisabled && { opacity: p.theme.elementEffect.disabled.opacity }}
150
- `
151
-
152
- const StyledInputContainer = styled.div<{
153
- invalid: boolean
154
- hasPrefix: boolean
155
- hasSuffix: boolean
156
- }>`
157
- display: grid;
158
- grid-template-columns: ${(p) =>
159
- [p.hasPrefix && 'auto', '1fr', p.hasSuffix && 'auto']
160
- .filter(Boolean)
161
- .join(' ')};
162
- height: 40px;
163
- transition: 0.2s background-color, 0.2s box-shadow;
164
- color: var(--charcoal-text2);
165
- background-color: var(--charcoal-surface3);
166
- border-radius: 4px;
167
- gap: 4px;
168
- padding: 0 8px;
169
- line-height: 22px;
170
- font-size: 14px;
171
-
172
- :not(:disabled):not([aria-disabled]):hover,
173
- [aria-disabled='false']:hover {
174
- background-color: var(--charcoal-surface3-hover);
175
- }
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 PrefixContainer = styled.div`
191
- display: flex;
192
- align-items: center;
193
- `
194
-
195
- const SuffixContainer = styled.span`
196
- display: flex;
197
- align-items: center;
198
- gap: 8px;
199
- `
200
-
201
- const StyledInput = styled.input<{
202
- invalid: boolean
203
- }>`
204
- border: none;
205
- box-sizing: border-box;
206
- outline: none;
207
- font-family: inherit;
208
-
209
- /* Prevent zooming for iOS Safari */
210
- transform-origin: top left;
211
- transform: scale(0.875);
212
- width: calc(100% / 0.875);
213
- height: calc(100% / 0.875);
214
- font-size: calc(14px / 0.875);
215
- line-height: calc(22px / 0.875);
216
- padding-left: 0;
217
- padding-right: 0;
218
- border-radius: calc(4px / 0.875);
219
-
220
- /* Display box-shadow for iOS Safari */
221
- appearance: none;
222
- background: transparent;
223
-
224
- color: var(--charcoal-text2);
225
- &::placeholder {
226
- color: var(--charcoal-text3);
227
- }
228
- `
229
-
230
- const SingleLineCounter = styled.span`
231
- line-height: 22px;
232
- font-size: 14px;
233
- color: var(--charcoal-text3);
234
- `
235
-
236
- export const AssistiveText = styled.p<{ invalid: boolean }>`
237
- font-size: 14px;
238
- line-height: 22px;
239
- margin: 0;
240
- color: ${(p) => `var(--charcoal-${p.invalid ? `assertive` : `text2`})`};
241
- `
@@ -1 +1,12 @@
1
- export { SSRProvider } from '@react-aria/ssr'
1
+ import { SSRProvider as OriginSSRProvider } from '@react-aria/ssr'
2
+ import { version, Fragment } from 'react'
3
+
4
+ export function isReactVersionOver(minVersion: number): boolean {
5
+ // version history on the react side: https://github.com/facebook/react/commits/main/packages/shared/ReactVersion.js
6
+ const reactMajorVersion = parseInt(version.split('.')[0], 10)
7
+ return Number.isFinite(reactMajorVersion)
8
+ ? reactMajorVersion >= minVersion
9
+ : false
10
+ }
11
+
12
+ export const SSRProvider = isReactVersionOver(18) ? Fragment : OriginSSRProvider
package/src/index.ts CHANGED
@@ -31,7 +31,11 @@ export {
31
31
  } from './components/TextField'
32
32
  export { default as TextArea, type TextAreaProps } from './components/TextArea'
33
33
  export { default as Icon, type IconProps } from './components/Icon'
34
- export { default as Modal, type ModalProps } from './components/Modal'
34
+ export {
35
+ default as Modal,
36
+ type ModalProps,
37
+ ModalCloseButton,
38
+ } from './components/Modal'
35
39
  export {
36
40
  ModalHeader,
37
41
  ModalAlign,