@charcoal-ui/react 3.3.0 → 3.4.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 (59) hide show
  1. package/dist/_lib/useForwardedRef.d.ts +3 -0
  2. package/dist/_lib/useForwardedRef.d.ts.map +1 -0
  3. package/dist/components/Clickable/index.d.ts.map +1 -1
  4. package/dist/components/DropdownSelector/DropdownPopover.d.ts.map +1 -1
  5. package/dist/components/DropdownSelector/Popover/index.d.ts.map +1 -1
  6. package/dist/components/DropdownSelector/Popover/usePreventScroll.d.ts +2 -0
  7. package/dist/components/DropdownSelector/Popover/usePreventScroll.d.ts.map +1 -0
  8. package/dist/components/DropdownSelector/index.story.d.ts +1 -0
  9. package/dist/components/DropdownSelector/index.story.d.ts.map +1 -1
  10. package/dist/components/Icon/index.story.d.ts +1 -1
  11. package/dist/components/Modal/Dialog/index.d.ts +26 -0
  12. package/dist/components/Modal/Dialog/index.d.ts.map +1 -0
  13. package/dist/components/Modal/ModalBackgroundContext.d.ts +6 -0
  14. package/dist/components/Modal/ModalBackgroundContext.d.ts.map +1 -0
  15. package/dist/components/Modal/ModalPlumbing.d.ts.map +1 -1
  16. package/dist/components/Modal/__stories__/InternalScrollStory.d.ts +4 -0
  17. package/dist/components/Modal/__stories__/InternalScrollStory.d.ts.map +1 -0
  18. package/dist/components/Modal/index.d.ts +12 -2
  19. package/dist/components/Modal/index.d.ts.map +1 -1
  20. package/dist/components/Modal/index.story.d.ts +3 -2
  21. package/dist/components/Modal/index.story.d.ts.map +1 -1
  22. package/dist/index.cjs.js +388 -299
  23. package/dist/index.cjs.js.map +1 -1
  24. package/dist/index.esm.js +350 -262
  25. package/dist/index.esm.js.map +1 -1
  26. package/package.json +6 -6
  27. package/src/_lib/useForwardedRef.tsx +16 -0
  28. package/src/components/Button/__snapshots__/index.story.storyshot +1971 -0
  29. package/src/components/Checkbox/__snapshots__/index.story.storyshot +390 -0
  30. package/src/components/Clickable/__snapshots__/index.story.storyshot +100 -0
  31. package/src/components/Clickable/index.tsx +17 -35
  32. package/src/components/DropdownSelector/DropdownPopover.tsx +0 -1
  33. package/src/components/DropdownSelector/ListItem/__snapshots__/index.story.storyshot +245 -0
  34. package/src/components/DropdownSelector/MenuList/__snapshots__/index.story.storyshot +555 -0
  35. package/src/components/DropdownSelector/Popover/__snapshots__/index.story.storyshot +174 -0
  36. package/src/components/DropdownSelector/Popover/index.tsx +17 -2
  37. package/src/components/DropdownSelector/Popover/usePreventScroll.tsx +18 -0
  38. package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +1241 -0
  39. package/src/components/DropdownSelector/index.story.tsx +69 -13
  40. package/src/components/Icon/__snapshots__/index.story.storyshot +12 -0
  41. package/src/components/{Button/__snapshots__/index.test.tsx.snap → IconButton/__snapshots__/index.story.storyshot} +94 -91
  42. package/src/components/LoadingSpinner/__snapshots__/index.story.storyshot +81 -0
  43. package/src/components/Modal/Dialog/index.tsx +82 -0
  44. package/src/components/Modal/ModalBackgroundContext.tsx +8 -0
  45. package/src/components/Modal/ModalPlumbing.tsx +16 -4
  46. package/src/components/Modal/__snapshots__/index.story.storyshot +533 -0
  47. package/src/components/Modal/__stories__/InternalScrollStory.tsx +75 -0
  48. package/src/components/Modal/index.story.tsx +57 -38
  49. package/src/components/Modal/index.tsx +63 -94
  50. package/src/components/MultiSelect/__snapshots__/index.story.storyshot +511 -0
  51. package/src/components/Radio/__snapshots__/index.story.storyshot +319 -0
  52. package/src/components/SegmentedControl/__snapshots__/index.story.storyshot +483 -0
  53. package/src/components/Switch/__snapshots__/index.story.storyshot +454 -0
  54. package/src/components/TagItem/__snapshots__/index.story.storyshot +1181 -0
  55. package/src/components/TextArea/__snapshots__/TextArea.story.storyshot +1271 -0
  56. package/src/components/TextField/__snapshots__/TextField.story.storyshot +1800 -0
  57. package/dist/components/Button/index.test.d.ts +0 -4
  58. package/dist/components/Button/index.test.d.ts.map +0 -1
  59. package/src/components/Button/index.test.tsx +0 -24
@@ -4,24 +4,21 @@ import {
4
4
  AriaModalOverlayProps,
5
5
  Overlay,
6
6
  useModalOverlay,
7
- useOverlay,
8
7
  } from '@react-aria/overlays'
9
8
  import styled, { css, useTheme } from 'styled-components'
10
9
  import { theme } from '../../styled'
11
- import { FocusScope } from '@react-aria/focus'
12
- import { useDialog } from '@react-aria/dialog'
13
10
  import { AriaDialogProps } from '@react-types/dialog'
14
- import { columnSystem, COLUMN_UNIT, GUTTER_UNIT } from '@charcoal-ui/foundation'
15
- import { unreachable } from '../../_lib'
16
11
  import { maxWidth } from '@charcoal-ui/utils'
17
12
  import { useMedia } from '@charcoal-ui/styled'
18
13
  import { animated, useTransition, easings } from 'react-spring'
19
14
  import Button, { ButtonProps } from '../Button'
20
15
  import IconButton from '../IconButton'
21
16
  import { useObjectRef } from '@react-aria/utils'
17
+ import { Dialog } from './Dialog'
18
+ import { ModalBackgroundContext } from './ModalBackgroundContext'
22
19
 
23
- type BottomSheet = boolean | 'full'
24
- type Size = 'S' | 'M' | 'L'
20
+ export type BottomSheet = boolean | 'full'
21
+ export type Size = 'S' | 'M' | 'L'
25
22
 
26
23
  export type ModalProps = AriaModalOverlayProps &
27
24
  AriaDialogProps & {
@@ -84,9 +81,8 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>(function ModalInner(
84
81
  } = props
85
82
 
86
83
  const ref = useObjectRef<HTMLDivElement>(external)
87
- const { overlayProps, underlayProps } = useOverlay(props, ref)
88
84
 
89
- const { modalProps } = useModalOverlay(
85
+ const { modalProps, underlayProps } = useModalOverlay(
90
86
  props,
91
87
  {
92
88
  close: onClose,
@@ -106,66 +102,76 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>(function ModalInner(
106
102
  ref
107
103
  )
108
104
 
109
- const { dialogProps, titleProps } = useDialog(props, ref)
110
-
111
105
  const theme = useTheme()
112
106
  const isMobile = useMedia(maxWidth(theme.breakpoint.screen1)) ?? false
113
107
  const transitionEnabled = isMobile && bottomSheet !== false
108
+ const showDismiss = !isMobile || bottomSheet !== true
109
+
114
110
  const transition = useTransition(isOpen, {
115
111
  from: {
116
112
  transform: 'translateY(100%)',
117
113
  backgroundColor: 'rgba(0, 0, 0, 0)',
114
+ overflow: 'hidden',
118
115
  },
119
116
  enter: {
120
117
  transform: 'translateY(0%)',
121
118
  backgroundColor: 'rgba(0, 0, 0, 0.4)',
122
119
  },
120
+ update: {
121
+ overflow: 'auto',
122
+ },
123
123
  leave: {
124
124
  transform: 'translateY(100%)',
125
125
  backgroundColor: 'rgba(0, 0, 0, 0)',
126
+ overflow: 'hidden',
126
127
  },
127
128
  config: transitionEnabled
128
129
  ? { duration: 400, easing: easings.easeOutQuart }
129
130
  : { duration: 0 },
130
131
  })
131
- const showDismiss = !isMobile || bottomSheet !== true
132
+
133
+ const bgRef = React.useRef<HTMLElement>(null)
132
134
 
133
135
  return transition(
134
- ({ backgroundColor, transform }, item) =>
136
+ ({ backgroundColor, overflow, transform }, item) =>
135
137
  item && (
136
138
  <Overlay portalContainer={portalContainer}>
137
139
  <ModalBackground
140
+ ref={bgRef}
138
141
  zIndex={zIndex}
139
142
  {...underlayProps}
140
- style={transitionEnabled ? { backgroundColor } : {}}
143
+ style={transitionEnabled ? { backgroundColor, overflow } : {}}
144
+ $bottomSheet={bottomSheet}
141
145
  >
142
- <FocusScope contain restoreFocus autoFocus>
143
- <DialogContainer bottomSheet={bottomSheet} size={size}>
144
- <ModalDialog
145
- ref={ref}
146
- {...overlayProps}
147
- {...modalProps}
148
- {...dialogProps}
149
- style={transitionEnabled ? { transform } : {}}
150
- size={size}
151
- bottomSheet={bottomSheet}
152
- className={className}
146
+ <ModalBackgroundContext.Provider value={bgRef.current}>
147
+ <Dialog
148
+ ref={ref}
149
+ {...modalProps}
150
+ style={transitionEnabled ? { transform } : {}}
151
+ size={size}
152
+ bottomSheet={bottomSheet}
153
+ className={className}
154
+ >
155
+ <ModalContext.Provider
156
+ value={{
157
+ titleProps: {},
158
+ title,
159
+ close: onClose,
160
+ showDismiss,
161
+ bottomSheet,
162
+ }}
153
163
  >
154
- <ModalContext.Provider
155
- value={{ titleProps, title, close: onClose, showDismiss }}
156
- >
157
- {children}
158
- {isDismissable === true && (
159
- <ModalCrossButton
160
- size="S"
161
- icon="24/Close"
162
- onClick={onClose}
163
- />
164
- )}
165
- </ModalContext.Provider>
166
- </ModalDialog>
167
- </DialogContainer>
168
- </FocusScope>
164
+ {children}
165
+ {isDismissable === true && (
166
+ <ModalCrossButton
167
+ size="S"
168
+ icon="24/Close"
169
+ onClick={onClose}
170
+ />
171
+ )}
172
+ </ModalContext.Provider>
173
+ </Dialog>
174
+ </ModalBackgroundContext.Provider>
169
175
  </ModalBackground>
170
176
  </Overlay>
171
177
  )
@@ -174,84 +180,47 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>(function ModalInner(
174
180
 
175
181
  export default memo(Modal)
176
182
 
177
- const ModalContext = React.createContext<{
183
+ export const ModalContext = React.createContext<{
184
+ /**
185
+ * @deprecated
186
+ */
178
187
  titleProps: React.HTMLAttributes<HTMLElement>
179
188
  title: string
180
189
  close?: () => void
181
190
  showDismiss: boolean
191
+ bottomSheet: BottomSheet
182
192
  }>({
183
193
  titleProps: {},
184
194
  title: '',
185
195
  close: undefined,
186
196
  showDismiss: true,
197
+ bottomSheet: false,
187
198
  })
188
199
 
189
- const ModalBackground = animated(styled.div<{ zIndex: number }>`
200
+ const ModalBackground = animated(styled.div<{
201
+ zIndex: number
202
+ $bottomSheet: BottomSheet
203
+ }>`
190
204
  z-index: ${({ zIndex }) => zIndex};
191
205
  overflow: auto;
192
206
  display: flex;
193
207
  position: fixed;
194
208
  top: 0;
195
209
  left: 0;
196
- width: 100%;
210
+ width: -webkit-fill-available;
211
+ width: -moz-available;
197
212
  height: 100%;
213
+ justify-content: center;
214
+ padding: 40px 0;
215
+ box-sizing: border-box;
198
216
 
199
- ${theme((o) => [o.bg.surface4])}
200
- `)
201
-
202
- const DialogContainer = styled.div<{ bottomSheet: BottomSheet; size: Size }>`
203
- position: relative;
204
- margin: auto;
205
- padding: 24px 0;
206
- width: ${(p) => {
207
- switch (p.size) {
208
- case 'S': {
209
- return columnSystem(3, COLUMN_UNIT, GUTTER_UNIT) + GUTTER_UNIT * 2
210
- }
211
- case 'M': {
212
- return columnSystem(4, COLUMN_UNIT, GUTTER_UNIT) + GUTTER_UNIT * 2
213
- }
214
- case 'L': {
215
- return columnSystem(6, COLUMN_UNIT, GUTTER_UNIT) + GUTTER_UNIT * 2
216
- }
217
- default: {
218
- return unreachable(p.size)
219
- }
220
- }
221
- }}px;
217
+ background-color: ${({ theme }) => theme.color.surface4};
222
218
 
223
219
  @media ${({ theme }) => maxWidth(theme.breakpoint.screen1)} {
224
- width: calc(100% - 48px);
225
220
  ${(p) =>
226
- p.bottomSheet !== false &&
221
+ p.$bottomSheet !== false &&
227
222
  css`
228
- margin: 0;
229
223
  padding: 0;
230
- bottom: 0;
231
- position: absolute;
232
- width: 100%;
233
- ${p.bottomSheet === 'full' ? 'height: 100%' : ''};
234
- `}
235
- }
236
- `
237
-
238
- const ModalDialog = animated(styled.div<{
239
- size: Size
240
- bottomSheet: BottomSheet
241
- }>`
242
- position: relative;
243
- margin: auto;
244
-
245
- ${theme((o) => [o.bg.background1, o.borderRadius(24)])}
246
- @media ${({ theme }) => maxWidth(theme.breakpoint.screen1)} {
247
- ${(p) =>
248
- p.bottomSheet !== false &&
249
- css`
250
- border-radius: 0;
251
- ${p.bottomSheet === 'full' &&
252
- css`
253
- height: 100%;
254
- `}
255
224
  `}
256
225
  }
257
226
  `)