@teamturing/react-kit 2.15.1 → 2.16.1

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.
@@ -0,0 +1,292 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import SvgCheck from '../../packages/icons/esm/Check.js';
3
+ import { noop } from '../../packages/utils/esm/noop.js';
4
+ import { r as reactIsExports } from '../../node_modules/react-is/index.js';
5
+ import styled, { css } from 'styled-components';
6
+ import '../../node_modules/styled-system/dist/index.esm.js';
7
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
8
+ import { isNullable } from '../../utils/isNullable.js';
9
+ import { sx } from '../../utils/styled-system/index.js';
10
+ import Grid from '../Grid/index.js';
11
+ import StyledIcon from '../StyledIcon/index.js';
12
+ import Text from '../Text/index.js';
13
+ import View from '../View/index.js';
14
+ import { ActionListContext } from './index.js';
15
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
16
+ import { variant } from '../../node_modules/@styled-system/variant/dist/index.esm.js';
17
+
18
+ const ActionListItem = ({
19
+ variant = 'neutral',
20
+ leadingVisual: LeadingVisual,
21
+ trailingVisual: TrailingVisual,
22
+ description,
23
+ descriptionLayout = 'block',
24
+ disabled = false,
25
+ selected = false,
26
+ onSelect: propOnSelect,
27
+ children,
28
+ sx
29
+ }) => {
30
+ const {
31
+ selectionVariant
32
+ } = useContext(ActionListContext);
33
+ if (!selectionVariant && selected) {
34
+ throw new Error('To use selected props in ActionList.Item, ActionList selectionVariant props should be defined.');
35
+ }
36
+ const handleSelect = useCallback(event => {
37
+ propOnSelect?.(event);
38
+ }, [propOnSelect]);
39
+ const handleClick = useCallback(event => {
40
+ if (disabled) return;
41
+ handleSelect(event);
42
+ }, [handleSelect, disabled]);
43
+ const handleKeyDown = useCallback(event => {
44
+ if (disabled) return;
45
+ if ([' ', 'Enter'].includes(event.key)) {
46
+ handleSelect(event);
47
+ }
48
+ }, [handleSelect, disabled]);
49
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(BaseActionListItem, {
50
+ variant: variant,
51
+ ...(disabled ? {
52
+ disabled
53
+ } : {
54
+ tabIndex: 0
55
+ }),
56
+ sx: sx,
57
+ onClick: handleClick,
58
+ onKeyDown: handleKeyDown,
59
+ children: [!isNullable(selectionVariant) ? /*#__PURE__*/jsxRuntimeExports.jsx(View, {
60
+ display: 'inline-flex',
61
+ minWidth: 20,
62
+ sx: {
63
+ 'mr': 2,
64
+ '& svg': {
65
+ color: 'icon/selected/violet'
66
+ }
67
+ },
68
+ children: selectionVariant === 'single' ? selected ? /*#__PURE__*/jsxRuntimeExports.jsx(StyledIcon, {
69
+ icon: SvgCheck,
70
+ size: 20
71
+ }) : null : selectionVariant === 'multiple' ? /*#__PURE__*/jsxRuntimeExports.jsx(FakeCheckbox, {
72
+ "aria-checked": selected,
73
+ checked: selected,
74
+ onChange: noop,
75
+ "aria-disabled": disabled,
76
+ disabled: disabled
77
+ }) : null
78
+ }) : null, /*#__PURE__*/jsxRuntimeExports.jsx(VisualWrapper, {
79
+ display: 'inline-flex',
80
+ flexShrink: 0,
81
+ sx: {
82
+ mr: LeadingVisual ? 2 : 0
83
+ },
84
+ variant: variant,
85
+ children: typeof LeadingVisual !== 'string' && reactIsExports.isValidElementType(LeadingVisual) ? /*#__PURE__*/jsxRuntimeExports.jsx(LeadingVisual, {}) : LeadingVisual
86
+ }), /*#__PURE__*/jsxRuntimeExports.jsx(View, {
87
+ flex: 1,
88
+ children: /*#__PURE__*/jsxRuntimeExports.jsxs(Grid, {
89
+ gapX: 2,
90
+ gapY: 0.5,
91
+ wrap: true,
92
+ alignItems: 'flex-end',
93
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(Grid.Unit, {
94
+ size: descriptionLayout === 'inline' ? 'min' : 1,
95
+ sx: {
96
+ fontWeight: description && descriptionLayout === 'block' ? 'bold' : 'medium'
97
+ },
98
+ children: children
99
+ }), /*#__PURE__*/jsxRuntimeExports.jsx(Grid.Unit, {
100
+ size: descriptionLayout === 'inline' ? 'max' : 1,
101
+ children: /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
102
+ typography: 'xxs/regular',
103
+ color: disabled ? 'text/disabled' : 'text/neutral/subtler',
104
+ children: description
105
+ })
106
+ })]
107
+ })
108
+ }), /*#__PURE__*/jsxRuntimeExports.jsx(VisualWrapper, {
109
+ display: 'inline-flex',
110
+ flexShrink: 0,
111
+ sx: {
112
+ ml: TrailingVisual ? 2 : 0
113
+ },
114
+ variant: variant,
115
+ children: typeof TrailingVisual !== 'string' && reactIsExports.isValidElementType(TrailingVisual) ? /*#__PURE__*/jsxRuntimeExports.jsx(TrailingVisual, {}) : TrailingVisual
116
+ })]
117
+ });
118
+ };
119
+ const VisualWrapper = styled(View)`
120
+ ${variant({
121
+ prop: 'variant',
122
+ variants: {
123
+ neutral: {
124
+ 'color': 'text/neutral',
125
+ '& svg': {
126
+ color: 'icon/neutral'
127
+ }
128
+ },
129
+ danger: {
130
+ 'color': 'text/danger',
131
+ '& svg': {
132
+ color: 'icon/danger'
133
+ }
134
+ }
135
+ }
136
+ })}
137
+ `;
138
+ const BaseActionListItem = styled.li`
139
+ display: flex;
140
+ align-items: flex-start;
141
+
142
+ font-size: ${({
143
+ theme
144
+ }) => forcePixelValue(theme.fontSizes.xs)};
145
+ font-weight: ${({
146
+ theme
147
+ }) => theme.fontWeights.medium};
148
+ line-height: ${({
149
+ theme
150
+ }) => theme.lineHeights[2]};
151
+
152
+ & svg {
153
+ width: ${forcePixelValue(20)};
154
+ height: ${forcePixelValue(20)};
155
+ }
156
+
157
+ padding: ${({
158
+ theme
159
+ }) => forcePixelValue(theme.space[3])};
160
+ background-color: ${({
161
+ theme
162
+ }) => theme.colors['bg/neutral/subtler']};
163
+ border-radius: ${({
164
+ theme
165
+ }) => forcePixelValue(theme.radii.xs)};
166
+ cursor: pointer;
167
+ transition: background-color 100ms;
168
+
169
+ ${({
170
+ theme,
171
+ disabled
172
+ }) => disabled ? css`
173
+ color: ${theme.colors['text/disabled']};
174
+ & svg {
175
+ color: ${({
176
+ theme
177
+ }) => theme.colors['icon/disabled']};
178
+ }
179
+ cursor: not-allowed;
180
+ ` : css`
181
+ &:hover {
182
+ background-color: ${theme.colors['bg/neutral/subtler/hovered']};
183
+ }
184
+ &:hover:active {
185
+ background-color: ${theme.colors['bg/neutral/subtler/pressed']};
186
+ }
187
+ &:focus-visible {
188
+ outline-width: ${forcePixelValue(2)};
189
+ outline-style: solid;
190
+ outline-color: ${theme.colors['border/focused']};
191
+ outline-offset: ${forcePixelValue(-2)};
192
+ }
193
+ `}
194
+
195
+ ${({
196
+ theme,
197
+ disabled,
198
+ variant
199
+ }) => !disabled && variant === 'danger' ? css`
200
+ color: ${theme.colors['text/danger']};
201
+ ` : !disabled && variant === 'neutral' ? css`
202
+ color: ${theme.colors['text/neutral']};
203
+ ` : null}
204
+
205
+ ${sx};
206
+ `;
207
+ const FakeCheckbox = styled.div`
208
+ position: relative;
209
+
210
+ width: ${forcePixelValue(20)};
211
+ height: ${forcePixelValue(20)};
212
+
213
+ border-width: ${forcePixelValue(2)};
214
+ border-style: solid;
215
+ border-color: ${({
216
+ theme
217
+ }) => theme.colors['border/neutral']};
218
+ border-radius: ${({
219
+ theme
220
+ }) => `${forcePixelValue(theme.radii.xxs)}`};
221
+ cursor: pointer;
222
+
223
+ transition: visibility 200ms;
224
+
225
+ &::before {
226
+ visibility: hidden;
227
+
228
+ content: '';
229
+ display: grid;
230
+ position: absolute;
231
+
232
+ top: 0;
233
+ right: 0;
234
+ bottom: 0;
235
+ left: 0;
236
+
237
+ border-radius: ${({
238
+ theme
239
+ }) => `${forcePixelValue(theme.radii.xxs)}`};
240
+
241
+ background-color: ${({
242
+ theme
243
+ }) => theme.colors['icon/inverse']};
244
+ mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10.6 17.2C10.3 17.2 10 17.1 9.80001 16.8L5.20001 12.2C4.70001 11.7 4.70001 11 5.20001 10.5C5.70001 9.99998 6.40001 9.99998 6.90001 10.5L10.6 14.2L17.2 7.59998C17.7 7.09998 18.4 7.09998 18.9 7.59998C19.4 8.09998 19.4 8.79998 18.9 9.29998L11.5 16.7C11.2 17.1 10.9 17.2 10.6 17.2Z' fill='%238D94A0'/%3E%3C/svg%3E%0A");
245
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10.6 17.2C10.3 17.2 10 17.1 9.80001 16.8L5.20001 12.2C4.70001 11.7 4.70001 11 5.20001 10.5C5.70001 9.99998 6.40001 9.99998 6.90001 10.5L10.6 14.2L17.2 7.59998C17.7 7.09998 18.4 7.09998 18.9 7.59998C19.4 8.09998 19.4 8.79998 18.9 9.29998L11.5 16.7C11.2 17.1 10.9 17.2 10.6 17.2Z' fill='%238D94A0'/%3E%3C/svg%3E%0A");
246
+ mask-size: 100%;
247
+ -webkit-mask-size: 100%;
248
+ mask-repeat: no-repeat;
249
+ -webkit-mask-repeat: no-repeat;
250
+ mask-position: center;
251
+ -webkit-mask-position: center;
252
+ }
253
+
254
+ &[aria-disabled='true'] {
255
+ background-color: ${({
256
+ theme
257
+ }) => theme.colors['bg/disabled']};
258
+ border-color: ${({
259
+ theme
260
+ }) => theme.colors['border/disabled']};
261
+ }
262
+
263
+ &[aria-checked='true'] {
264
+ background-color: ${({
265
+ theme
266
+ }) => theme.colors['bg/primary']};
267
+ border-width: 0;
268
+
269
+ &::before {
270
+ visibility: visible;
271
+ }
272
+
273
+ &[aria-disabled='true'] {
274
+ background-color: ${({
275
+ theme
276
+ }) => theme.colors['bg/disabled']};
277
+ border-color: ${({
278
+ theme
279
+ }) => theme.colors['border/disabled']};
280
+
281
+ &::before {
282
+ background-color: ${({
283
+ theme
284
+ }) => theme.colors['icon/disabled']};
285
+ }
286
+ }
287
+ }
288
+
289
+ ${sx}
290
+ `;
291
+
292
+ export { ActionListItem as default };
@@ -0,0 +1,20 @@
1
+ import HorizontalDivider from '../HorizontalDivider/index.js';
2
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
3
+
4
+ const ActionListSectionDivider = ({
5
+ color = 'border/neutral',
6
+ variant = 'solid',
7
+ width = 1,
8
+ sx
9
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(BaseActionListSectionDivider, {
10
+ color: color,
11
+ variant: variant,
12
+ width: width,
13
+ sx: {
14
+ ...sx,
15
+ my: 3
16
+ }
17
+ });
18
+ const BaseActionListSectionDivider = HorizontalDivider;
19
+
20
+ export { ActionListSectionDivider as default };
@@ -0,0 +1,37 @@
1
+ import styled from 'styled-components';
2
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
3
+ import { sx } from '../../utils/styled-system/index.js';
4
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
5
+
6
+ const ActionListSectionHeader = ({
7
+ ...props
8
+ }) => {
9
+ return /*#__PURE__*/jsxRuntimeExports.jsx(BaseActionListSectionHeader, {
10
+ role: 'presentation',
11
+ ...props
12
+ });
13
+ };
14
+ const BaseActionListSectionHeader = styled.div`
15
+ color: ${({
16
+ theme
17
+ }) => theme.colors['text/neutral/subtlest']};
18
+ font-size: ${({
19
+ theme
20
+ }) => forcePixelValue(theme.fontSizes.xxs)};
21
+ font-weight: ${({
22
+ theme
23
+ }) => theme.fontWeights.bold};
24
+ line-height: ${({
25
+ theme
26
+ }) => theme.lineHeights[2]};
27
+
28
+ white-space: pre-wrap;
29
+
30
+ padding: ${({
31
+ theme
32
+ }) => `${forcePixelValue(theme.space[1])} ${forcePixelValue(theme.space[3])}}`};
33
+
34
+ ${sx};
35
+ `;
36
+
37
+ export { ActionListSectionHeader as default };
@@ -0,0 +1,36 @@
1
+ import { createContext } from 'react';
2
+ import styled from 'styled-components';
3
+ import { sx } from '../../utils/styled-system/index.js';
4
+ import ActionListItem from './ActionListItem.js';
5
+ import ActionListSectionDivider from './ActionListSectionDivider.js';
6
+ import ActionListSectionHeader from './ActionListSectionHeader.js';
7
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
8
+
9
+ const ActionListContext = /*#__PURE__*/createContext({});
10
+ const ActionList = ({
11
+ ...props
12
+ }) => {
13
+ return /*#__PURE__*/jsxRuntimeExports.jsx(ActionListContext.Provider, {
14
+ value: {
15
+ selectionVariant: props.selectionVariant
16
+ },
17
+ children: /*#__PURE__*/jsxRuntimeExports.jsx(BaseActionList, {
18
+ role: 'menu',
19
+ ...props
20
+ })
21
+ });
22
+ };
23
+ const BaseActionList = styled.ul`
24
+ list-style: none;
25
+ padding: 0;
26
+ margin: 0;
27
+
28
+ ${sx}
29
+ `;
30
+ var index = Object.assign(ActionList, {
31
+ Item: ActionListItem,
32
+ SectionDivider: ActionListSectionDivider,
33
+ SectionHeader: ActionListSectionHeader
34
+ });
35
+
36
+ export { ActionListContext, index as default };
@@ -13,11 +13,19 @@ const Overlay = ({
13
13
  onDismiss,
14
14
  size = 'm',
15
15
  ignoreOutsideClickRefs = [],
16
+ dismissFocusRef,
16
17
  ...props
17
18
  }, ref) => {
18
19
  const overlayRef = useRef(null);
19
20
  useImperativeHandle(ref, () => overlayRef.current);
20
- const handleDismiss = useCallback(() => onDismiss?.(), [onDismiss]);
21
+ const handleDismiss = useCallback(() => {
22
+ if (dismissFocusRef && dismissFocusRef.current) {
23
+ setTimeout(() => {
24
+ dismissFocusRef.current?.focus();
25
+ }, 0);
26
+ }
27
+ onDismiss?.();
28
+ }, [onDismiss]);
21
29
  const handleOutsideClick = useCallback(e => {
22
30
  if (overlayRef.current && e.target instanceof Node && !overlayRef.current.contains(e.target) && ignoreOutsideClickRefs && !ignoreOutsideClickRefs.some(({
23
31
  current
@@ -56,6 +56,7 @@ const OverlayPopper = ({
56
56
  ref: refs.setFloating,
57
57
  isOpen: isOpen,
58
58
  onDismiss: closeOverlay,
59
+ dismissFocusRef: refs.reference,
59
60
  ignoreOutsideClickRefs: [refs.reference],
60
61
  style: floatingStyles,
61
62
  children: renderOverlay({
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { default as ActionList } from './core/ActionList/index.js';
1
2
  export { default as Avatar } from './core/Avatar/index.js';
2
3
  export { default as Breadcrumbs } from './core/Breadcrumbs/index.js';
3
4
  export { default as Button } from './core/Button/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.15.1",
3
+ "version": "2.16.1",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -62,5 +62,5 @@
62
62
  "react-is": "^18.2.0",
63
63
  "styled-system": "^5.1.5"
64
64
  },
65
- "gitHead": "4dd8a356f2d54ce591d4f7b988f92b8098c500ef"
65
+ "gitHead": "b202599554a5c0aaf45652c3f5815d171b7ba8fb"
66
66
  }