@primer/components 0.0.0-202192801738 → 0.0.0-2021928142718

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 (112) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/browser.esm.js +616 -616
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +177 -177
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Description.d.ts +6 -0
  7. package/lib/ActionList2/Description.js +53 -0
  8. package/lib/ActionList2/Divider.d.ts +5 -0
  9. package/lib/ActionList2/Divider.js +33 -0
  10. package/lib/ActionList2/Group.d.ts +8 -0
  11. package/lib/ActionList2/Group.js +46 -0
  12. package/lib/ActionList2/Header.d.ts +26 -0
  13. package/lib/ActionList2/Header.js +55 -0
  14. package/lib/ActionList2/Item.d.ts +48 -0
  15. package/lib/ActionList2/Item.js +204 -0
  16. package/lib/ActionList2/List.d.ts +26 -0
  17. package/lib/ActionList2/List.js +56 -0
  18. package/lib/ActionList2/Selection.d.ts +5 -0
  19. package/lib/ActionList2/Selection.js +64 -0
  20. package/lib/ActionList2/Visuals.d.ts +11 -0
  21. package/lib/ActionList2/Visuals.js +90 -0
  22. package/lib/ActionList2/hacks.d.ts +30 -0
  23. package/lib/ActionList2/hacks.js +38 -0
  24. package/lib/ActionList2/index.d.ts +25 -0
  25. package/lib/ActionList2/index.js +36 -0
  26. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  27. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  29. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  30. package/lib/TextInputWithTokens.d.ts +2 -4
  31. package/lib/index.d.ts +1 -0
  32. package/lib/index.js +8 -0
  33. package/lib/sx.d.ts +2 -0
  34. package/lib/sx.js +8 -0
  35. package/lib/theme-preval.js +2 -2
  36. package/lib/utils/create-slots.d.ts +17 -0
  37. package/lib/utils/create-slots.js +105 -0
  38. package/lib/utils/testing.d.ts +1 -1
  39. package/lib/utils/use-force-update.d.ts +1 -0
  40. package/lib/utils/use-force-update.js +19 -0
  41. package/lib-esm/ActionList2/Description.d.ts +6 -0
  42. package/lib-esm/ActionList2/Description.js +37 -0
  43. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  44. package/lib-esm/ActionList2/Divider.js +21 -0
  45. package/lib-esm/ActionList2/Group.d.ts +8 -0
  46. package/lib-esm/ActionList2/Group.js +35 -0
  47. package/lib-esm/ActionList2/Header.d.ts +26 -0
  48. package/lib-esm/ActionList2/Header.js +45 -0
  49. package/lib-esm/ActionList2/Item.d.ts +48 -0
  50. package/lib-esm/ActionList2/Item.js +176 -0
  51. package/lib-esm/ActionList2/List.d.ts +26 -0
  52. package/lib-esm/ActionList2/List.js +38 -0
  53. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  54. package/lib-esm/ActionList2/Selection.js +48 -0
  55. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  56. package/lib-esm/ActionList2/Visuals.js +68 -0
  57. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  58. package/lib-esm/ActionList2/hacks.js +30 -0
  59. package/lib-esm/ActionList2/index.d.ts +25 -0
  60. package/lib-esm/ActionList2/index.js +23 -0
  61. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  62. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  63. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  64. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  65. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  66. package/lib-esm/index.d.ts +1 -0
  67. package/lib-esm/index.js +1 -0
  68. package/lib-esm/sx.d.ts +2 -0
  69. package/lib-esm/sx.js +3 -1
  70. package/lib-esm/theme-preval.js +2 -2
  71. package/lib-esm/utils/create-slots.d.ts +17 -0
  72. package/lib-esm/utils/create-slots.js +84 -0
  73. package/lib-esm/utils/testing.d.ts +1 -1
  74. package/lib-esm/utils/use-force-update.d.ts +1 -0
  75. package/lib-esm/utils/use-force-update.js +6 -0
  76. package/package.json +8 -9
  77. package/lib/DatePicker/DatePicker.d.ts +0 -48
  78. package/lib/DatePicker/DatePicker.js +0 -104
  79. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  80. package/lib/DatePicker/DatePickerAnchor.js +0 -182
  81. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  82. package/lib/DatePicker/DatePickerOverlay.js +0 -48
  83. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  84. package/lib/DatePicker/DatePickerPanel.js +0 -126
  85. package/lib/DatePicker/Day.d.ts +0 -14
  86. package/lib/DatePicker/Day.js +0 -190
  87. package/lib/DatePicker/Month.d.ts +0 -9
  88. package/lib/DatePicker/Month.js +0 -120
  89. package/lib/DatePicker/index.d.ts +0 -2
  90. package/lib/DatePicker/index.js +0 -13
  91. package/lib/DatePicker/useDatePicker.d.ts +0 -88
  92. package/lib/DatePicker/useDatePicker.js +0 -438
  93. package/lib/hooks/useDebounce.d.ts +0 -2
  94. package/lib/hooks/useDebounce.js +0 -24
  95. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  96. package/lib-esm/DatePicker/DatePicker.js +0 -87
  97. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  98. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -155
  99. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  100. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
  101. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  102. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  103. package/lib-esm/DatePicker/Day.d.ts +0 -14
  104. package/lib-esm/DatePicker/Day.js +0 -167
  105. package/lib-esm/DatePicker/Month.d.ts +0 -9
  106. package/lib-esm/DatePicker/Month.js +0 -96
  107. package/lib-esm/DatePicker/index.d.ts +0 -2
  108. package/lib-esm/DatePicker/index.js +0 -1
  109. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -88
  110. package/lib-esm/DatePicker/useDatePicker.js +0 -408
  111. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  112. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -0,0 +1,35 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ /**
4
+ * show item dividers
5
+ */
6
+ import React from 'react';
7
+ import Box from '../Box';
8
+ import { Header } from './Header';
9
+ export const Group = ({
10
+ title,
11
+ variant,
12
+ auxiliaryText,
13
+ sx = {},
14
+ ...props
15
+ }) => {
16
+ return /*#__PURE__*/React.createElement(Box, _extends({
17
+ as: "li",
18
+ sx: {
19
+ '&:not(:first-child)': {
20
+ marginTop: 2
21
+ },
22
+ ...sx
23
+ }
24
+ }, props), title && /*#__PURE__*/React.createElement(Header, {
25
+ title: title,
26
+ variant: variant,
27
+ auxiliaryText: auxiliaryText
28
+ }), /*#__PURE__*/React.createElement(Box, {
29
+ as: "ul",
30
+ sx: {
31
+ paddingInlineStart: 0
32
+ }
33
+ }, props.children));
34
+ };
35
+ Group.displayName = "Group";
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { SxProp } from '../sx';
3
+ /**
4
+ * Contract for props passed to the `Header` component.
5
+ */
6
+ export interface HeaderProps extends React.ComponentPropsWithoutRef<'div'>, SxProp {
7
+ /**
8
+ * Style variations. Usage is discretionary.
9
+ *
10
+ * - `"filled"` - Superimposed on a background, offset from nearby content
11
+ * - `"subtle"` - Relatively less offset from nearby content
12
+ */
13
+ variant?: 'subtle' | 'filled';
14
+ /**
15
+ * Primary text which names a `Group`.
16
+ */
17
+ title?: string;
18
+ /**
19
+ * Secondary text which provides additional information about a `Group`.
20
+ */
21
+ auxiliaryText?: string;
22
+ }
23
+ /**
24
+ * Displays the name and description of a `Group`.
25
+ */
26
+ export declare function Header({ variant, title, auxiliaryText, children: _children, sx, ...props }: HeaderProps): JSX.Element;
@@ -0,0 +1,45 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import Box from '../Box';
5
+ import { ListContext } from './List';
6
+ /**
7
+ * Contract for props passed to the `Header` component.
8
+ */
9
+
10
+ /**
11
+ * Displays the name and description of a `Group`.
12
+ */
13
+ export function Header({
14
+ variant = 'subtle',
15
+ title,
16
+ auxiliaryText,
17
+ children: _children,
18
+ sx = {},
19
+ ...props
20
+ }) {
21
+ const {
22
+ variant: listVariant
23
+ } = React.useContext(ListContext);
24
+ const styles = {
25
+ paddingY: '6px',
26
+ paddingX: listVariant === 'full' ? 2 : 3,
27
+ fontSize: 0,
28
+ fontWeight: 'bold',
29
+ color: 'fg.muted',
30
+ ...(variant === 'filled' && {
31
+ backgroundColor: 'canvas.subtle',
32
+ marginX: 0,
33
+ marginBottom: 2,
34
+ borderTop: '1px solid',
35
+ borderBottom: '1px solid',
36
+ borderColor: 'neutral.muted'
37
+ }),
38
+ ...sx
39
+ };
40
+ return /*#__PURE__*/React.createElement(Box, _extends({
41
+ sx: styles,
42
+ role: "heading"
43
+ }, props), title, auxiliaryText && /*#__PURE__*/React.createElement("span", null, "auxiliaryText"));
44
+ }
45
+ Header.displayName = "Header";
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
+ import { SxProp } from '../sx';
4
+ import { AriaRole } from '../utils/types';
5
+ export declare const getVariantStyles: (variant: ItemProps['variant'], disabled: ItemProps['disabled']) => {
6
+ color: string;
7
+ iconColor: string;
8
+ annotationColor: string;
9
+ };
10
+ export declare type ItemProps = {
11
+ /**
12
+ * Primary content for an Item
13
+ */
14
+ children: React.ReactNode;
15
+ /**
16
+ * Callback that will trigger both on click selection and keyboard selection.
17
+ */
18
+ onSelect?: (event: React.MouseEvent<HTMLLIElement> | React.KeyboardEvent<HTMLLIElement>) => void;
19
+ /**
20
+ * Is the `Item` is currently selected?
21
+ */
22
+ selected?: boolean;
23
+ /**
24
+ * Style variations associated with various `Item` types.
25
+ *
26
+ * - `"default"` - An action `Item`.
27
+ * - `"danger"` - A destructive action `Item`.
28
+ */
29
+ variant?: 'default' | 'danger';
30
+ /**
31
+ * Items that are disabled can not be clicked, selected, or navigated through.
32
+ */
33
+ disabled?: boolean;
34
+ /**
35
+ * The ARIA role describing the function of `Item` component. `option` is a common value. |
36
+ */
37
+ role?: AriaRole;
38
+ } & SxProp;
39
+ declare const Slot: React.FC<{
40
+ name: "LeadingVisual" | "InlineDescription" | "BlockDescription" | "TrailingVisual";
41
+ children: React.ReactNode | ((context: Record<string, unknown>) => React.ReactNode);
42
+ }>;
43
+ export { Slot };
44
+ export declare type ItemContext = Pick<ItemProps, 'variant' | 'disabled'> & {
45
+ inlineDescriptionId: string;
46
+ blockDescriptionId: string;
47
+ };
48
+ export declare const Item: PolymorphicForwardRefComponent<"li", ItemProps>;
@@ -0,0 +1,176 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import { useSSRSafeId } from '@react-aria/ssr';
5
+ import { useColorSchemeVar, useTheme } from '../ThemeProvider';
6
+ import Box from '../Box';
7
+ import { get } from '../constants';
8
+ import { merge } from '../sx';
9
+ import createSlots from '../utils/create-slots';
10
+ import { ListContext } from './List';
11
+ import { customItemThemes } from './hacks';
12
+ import { Selection } from './Selection';
13
+ export const getVariantStyles = (variant, disabled) => {
14
+ if (disabled) {
15
+ return {
16
+ color: 'fg.muted',
17
+ iconColor: 'fg.muted',
18
+ annotationColor: 'fg.muted'
19
+ };
20
+ }
21
+
22
+ switch (variant) {
23
+ case 'danger':
24
+ return {
25
+ color: 'danger.fg',
26
+ iconColor: 'danger.fg',
27
+ annotationColor: 'fg.muted'
28
+ };
29
+
30
+ default:
31
+ return {
32
+ color: 'fg.default',
33
+ iconColor: 'fg.muted',
34
+ annotationColor: 'fg.muted'
35
+ };
36
+ }
37
+ };
38
+ const {
39
+ Slots,
40
+ Slot
41
+ } = createSlots(['LeadingVisual', 'InlineDescription', 'BlockDescription', 'TrailingVisual']);
42
+ export { Slot };
43
+ export const Item = /*#__PURE__*/React.forwardRef(({
44
+ variant = 'default',
45
+ disabled = false,
46
+ selected = undefined,
47
+ onSelect = () => null,
48
+ sx = {},
49
+ ...props
50
+ }, forwardedRef) => {
51
+ const customItemTheme = customItemThemes[variant];
52
+ const {
53
+ variant: listVariant,
54
+ showDividers
55
+ } = React.useContext(ListContext);
56
+ const {
57
+ theme
58
+ } = useTheme();
59
+ const styles = {
60
+ display: 'flex',
61
+ paddingX: get('space.2'),
62
+ paddingY: '6px',
63
+ marginX: listVariant === 'inset' ? get('space.2') : 0,
64
+ minHeight: get('space.5'),
65
+ borderRadius: get('radii.2'),
66
+ transition: 'background 33.333ms linear',
67
+ color: getVariantStyles(variant, disabled).color,
68
+ textDecoration: 'none',
69
+ // for as="a"
70
+ ':not([aria-disabled])': {
71
+ cursor: 'pointer'
72
+ },
73
+ '@media (hover: hover) and (pointer: fine)': {
74
+ ':hover:not([aria-disabled])': {
75
+ backgroundColor: useColorSchemeVar(customItemTheme.hover, 'inherit')
76
+ },
77
+ ':focus:not([aria-disabled])': {
78
+ backgroundColor: useColorSchemeVar(customItemTheme.focus, 'inherit')
79
+ }
80
+ },
81
+
82
+ /** Divider styles */
83
+ '[data-component="ActionList.Item--DividerContainer"]': {
84
+ position: 'relative'
85
+ },
86
+ '[data-component="ActionList.Item--DividerContainer"]::before': {
87
+ content: '" "',
88
+ display: 'block',
89
+ position: 'absolute',
90
+ width: '100%',
91
+ top: '-7px',
92
+ border: '0 solid',
93
+ borderTopWidth: showDividers ? `1px` : '0',
94
+ borderColor: 'var(--divider-color, transparent)'
95
+ },
96
+ // show between 2 items
97
+ ':not(:first-of-type)': {
98
+ '--divider-color': theme === null || theme === void 0 ? void 0 : theme.colors.border.muted
99
+ },
100
+ // hide divider after dividers & group header
101
+ '[data-component="ActionList.Divider"] + &': {
102
+ '--divider-color': 'transparent'
103
+ },
104
+ // hide border on current and previous item
105
+ '&:hover:not([aria-disabled]), &:focus:not([aria-disabled])': {
106
+ '--divider-color': 'transparent'
107
+ },
108
+ '&:hover:not([aria-disabled]) + &, &:focus:not([aria-disabled]) + &': {
109
+ '--divider-color': 'transparent'
110
+ }
111
+ };
112
+ const clickHandler = React.useCallback(event => {
113
+ if (disabled) return;
114
+ if (!event.defaultPrevented) onSelect(event);
115
+ }, [onSelect, disabled]);
116
+ const labelId = useSSRSafeId();
117
+ const inlineDescriptionId = useSSRSafeId();
118
+ const blockDescriptionId = useSSRSafeId();
119
+ return /*#__PURE__*/React.createElement(Slots, {
120
+ context: {
121
+ variant,
122
+ disabled,
123
+ inlineDescriptionId,
124
+ blockDescriptionId
125
+ }
126
+ }, slots => /*#__PURE__*/React.createElement(Box, _extends({
127
+ as: "li",
128
+ ref: forwardedRef,
129
+ sx: merge(styles, sx),
130
+ onClick: clickHandler,
131
+ "aria-selected": selected,
132
+ "aria-disabled": disabled ? true : undefined,
133
+ "aria-labelledby": labelId,
134
+ "aria-describedby": [slots.InlineDescription && inlineDescriptionId, slots.BlockDescription && blockDescriptionId].filter(Boolean).join(' ')
135
+ }, props), /*#__PURE__*/React.createElement(Selection, {
136
+ selected: selected,
137
+ disabled: disabled
138
+ }), slots.LeadingVisual, /*#__PURE__*/React.createElement(Box, {
139
+ "data-component": "ActionList.Item--DividerContainer",
140
+ sx: {
141
+ display: 'flex',
142
+ flexDirection: 'column',
143
+ flexGrow: 1,
144
+ minWidth: 0
145
+ }
146
+ }, /*#__PURE__*/React.createElement(ConditionalBox, {
147
+ if: Boolean(slots.TrailingVisual),
148
+ sx: {
149
+ display: 'flex',
150
+ flexGrow: 1
151
+ }
152
+ }, /*#__PURE__*/React.createElement(ConditionalBox, {
153
+ if: Boolean(slots.InlineDescription),
154
+ sx: {
155
+ display: 'flex',
156
+ flexGrow: 1,
157
+ alignItems: 'baseline',
158
+ minWidth: 0
159
+ }
160
+ }, /*#__PURE__*/React.createElement(Box, {
161
+ as: "span",
162
+ id: labelId,
163
+ sx: {
164
+ flexGrow: slots.InlineDescription ? 0 : 1
165
+ }
166
+ }, props.children), slots.InlineDescription), slots.TrailingVisual), slots.BlockDescription)));
167
+ });
168
+ Item.displayName = 'ActionList.Item';
169
+
170
+ const ConditionalBox = props => {
171
+ const {
172
+ if: condition,
173
+ ...rest
174
+ } = props;
175
+ if (condition) return /*#__PURE__*/React.createElement(Box, rest, props.children);else return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
176
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
+ import { SxProp } from '../sx';
4
+ import { AriaRole } from '../utils/types';
5
+ export declare type ListProps = {
6
+ /**
7
+ * `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges
8
+ */
9
+ variant?: 'inset' | 'full';
10
+ /**
11
+ * Whether multiple Items or a single Item can be selected.
12
+ */
13
+ selectionVariant?: 'single' | 'multiple';
14
+ /**
15
+ * Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`.
16
+ */
17
+ showDividers?: boolean;
18
+ /**
19
+ * The ARIA role describing the function of `List` component. `listbox` or `menu` are a common values.
20
+ */
21
+ role?: AriaRole;
22
+ } & SxProp;
23
+ declare type ContextProps = Omit<ListProps, 'sx'>;
24
+ export declare const ListContext: React.Context<ContextProps>;
25
+ export declare const List: PolymorphicForwardRefComponent<"ul", ListProps>;
26
+ export {};
@@ -0,0 +1,38 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import Box from '../Box';
5
+ import { get } from '../constants';
6
+ import { merge } from '../sx';
7
+ export const ListContext = /*#__PURE__*/React.createContext({});
8
+ export const List = /*#__PURE__*/React.forwardRef(({
9
+ variant = 'inset',
10
+ selectionVariant,
11
+ showDividers = false,
12
+ sx = {},
13
+ ...props
14
+ }, forwardedRef) => {
15
+ const styles = {
16
+ margin: 0,
17
+ fontSize: get('fontSizes.1'),
18
+ lineHeight: '20px',
19
+ // TODO: check if we replace this already
20
+ paddingInlineStart: 0,
21
+ // reset ul styles
22
+ paddingY: variant === 'inset' ? get('space.2') : 0
23
+ };
24
+ return /*#__PURE__*/React.createElement(Box, _extends({
25
+ as: "ul",
26
+ sx: merge(styles, sx),
27
+ "aria-multiselectable": selectionVariant === 'multiple' ? true : undefined
28
+ }, props, {
29
+ ref: forwardedRef
30
+ }), /*#__PURE__*/React.createElement(ListContext.Provider, {
31
+ value: {
32
+ variant,
33
+ selectionVariant,
34
+ showDividers
35
+ }
36
+ }, props.children));
37
+ });
38
+ List.displayName = 'ActionList';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { ItemProps } from './Item';
3
+ declare type SelectionProps = Pick<ItemProps, 'selected' | 'disabled'>;
4
+ export declare const Selection: React.FC<SelectionProps>;
5
+ export {};
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { CheckIcon } from '@primer/octicons-react';
3
+ import { ListContext } from './List';
4
+ import { LeadingVisualContainer } from './Visuals';
5
+ export const Selection = ({
6
+ selected,
7
+ disabled
8
+ }) => {
9
+ const {
10
+ selectionVariant
11
+ } = React.useContext(ListContext); // if selectionVariant is not set on List, don't show selection
12
+
13
+ if (!selectionVariant) {
14
+ // to avoid confusion, fail loudly instead of silently ignoring
15
+ if (selected) throw new Error('For Item to be selected, List needs to have a selectionVariant defined');
16
+ return null;
17
+ }
18
+
19
+ if (selectionVariant === 'single') {
20
+ return /*#__PURE__*/React.createElement(LeadingVisualContainer, null, selected && /*#__PURE__*/React.createElement(CheckIcon, null));
21
+ }
22
+ /**
23
+ * selectionVariant is multiple
24
+ * readOnly is required because we are doing a one-way bind to `checked`
25
+ * aria-readonly="false" tells screen that they can still interact with the checkbox
26
+ * TODO: not sure if disabled & aria-label be here or should we apply it on the instance as props
27
+ * TODO: aria-label should come from the text part of the slot
28
+ */
29
+
30
+
31
+ return /*#__PURE__*/React.createElement(LeadingVisualContainer, {
32
+ sx: {
33
+ input: {
34
+ margin: 0,
35
+ pointerEvents: 'none'
36
+ }
37
+ }
38
+ }, /*#__PURE__*/React.createElement("input", {
39
+ type: "checkbox",
40
+ checked: selected,
41
+ disabled: disabled,
42
+ "aria-label": "TODO",
43
+ tabIndex: -1,
44
+ readOnly: true,
45
+ "aria-readonly": "false"
46
+ }));
47
+ };
48
+ Selection.displayName = "Selection";
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { SxProp } from '../sx';
3
+ declare type VisualProps = SxProp & {
4
+ children: React.ReactNode;
5
+ };
6
+ export declare const LeadingVisualContainer: React.FC<SxProp>;
7
+ export declare type LeadingVisualProps = VisualProps;
8
+ export declare const LeadingVisual: React.FC<VisualProps>;
9
+ export declare type TrailingVisualProps = VisualProps;
10
+ export declare const TrailingVisual: React.FC<VisualProps>;
11
+ export {};
@@ -0,0 +1,68 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import Box from '../Box';
5
+ import { merge } from '../sx';
6
+ import { get } from '../constants';
7
+ import { getVariantStyles, Slot } from './Item';
8
+ export const LeadingVisualContainer = ({
9
+ sx = {},
10
+ ...props
11
+ }) => {
12
+ return /*#__PURE__*/React.createElement(Box, _extends({
13
+ as: "span",
14
+ sx: merge({
15
+ height: '20px',
16
+ // match height of text row
17
+ minWidth: get('space.3'),
18
+ maxWidth: '20px',
19
+ // square (same as height)
20
+ display: 'flex',
21
+ justifyContent: 'center',
22
+ alignItems: 'center',
23
+ flexShrink: 0,
24
+ marginRight: 2
25
+ }, sx)
26
+ }, props));
27
+ };
28
+ LeadingVisualContainer.displayName = "LeadingVisualContainer";
29
+ export const LeadingVisual = ({
30
+ sx = {},
31
+ ...props
32
+ }) => {
33
+ return /*#__PURE__*/React.createElement(Slot, {
34
+ name: "LeadingVisual"
35
+ }, ({
36
+ variant,
37
+ disabled
38
+ }) => /*#__PURE__*/React.createElement(LeadingVisualContainer, _extends({
39
+ sx: merge({
40
+ color: getVariantStyles(variant, disabled).iconColor,
41
+ svg: {
42
+ fontSize: 0
43
+ }
44
+ }, sx)
45
+ }, props), props.children));
46
+ };
47
+ LeadingVisual.displayName = "LeadingVisual";
48
+ export const TrailingVisual = ({
49
+ sx = {},
50
+ ...props
51
+ }) => {
52
+ return /*#__PURE__*/React.createElement(Slot, {
53
+ name: "TrailingVisual"
54
+ }, ({
55
+ variant,
56
+ disabled
57
+ }) => /*#__PURE__*/React.createElement(Box, _extends({
58
+ as: "span",
59
+ sx: merge({
60
+ height: '20px',
61
+ // match height of text row
62
+ flexShrink: 0,
63
+ color: getVariantStyles(variant, disabled).annotationColor,
64
+ marginLeft: 2
65
+ }, sx)
66
+ }, props), props.children));
67
+ };
68
+ TrailingVisual.displayName = "TrailingVisual";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * These colors are not yet in our default theme.
3
+ * TODO: Need to remove this once they are added.
4
+ */
5
+ export declare const customItemThemes: {
6
+ default: {
7
+ hover: {
8
+ light: string;
9
+ dark: string;
10
+ dark_dimmed: string;
11
+ };
12
+ focus: {
13
+ light: string;
14
+ dark: string;
15
+ dark_dimmed: string;
16
+ };
17
+ };
18
+ danger: {
19
+ hover: {
20
+ light: string;
21
+ dark: string;
22
+ dark_dimmed: string;
23
+ };
24
+ focus: {
25
+ light: string;
26
+ dark: string;
27
+ dark_dimmed: string;
28
+ };
29
+ };
30
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * These colors are not yet in our default theme.
3
+ * TODO: Need to remove this once they are added.
4
+ */
5
+ export const customItemThemes = {
6
+ default: {
7
+ hover: {
8
+ light: 'rgba(46, 77, 108, 0.06)',
9
+ dark: 'rgba(201, 206, 212, 0.12)',
10
+ dark_dimmed: 'rgba(201, 206, 212, 0.12)'
11
+ },
12
+ focus: {
13
+ light: 'rgba(54, 77, 100, 0.16)',
14
+ dark: 'rgba(201, 206, 212, 0.24)',
15
+ dark_dimmed: 'rgba(201, 206, 212, 0.24)'
16
+ }
17
+ },
18
+ danger: {
19
+ hover: {
20
+ light: 'rgba(234, 74, 90, 0.08)',
21
+ dark: 'rgba(248, 81, 73, 0.16)',
22
+ dark_dimmed: 'rgba(248, 81, 73, 0.16)'
23
+ },
24
+ focus: {
25
+ light: 'rgba(234, 74, 90, 0.14)',
26
+ dark: 'rgba(248, 81, 73, 0.24)',
27
+ dark_dimmed: 'rgba(248, 81, 73, 0.24)'
28
+ }
29
+ }
30
+ };
@@ -0,0 +1,25 @@
1
+ /// <reference types="react" />
2
+ import { Divider } from './Divider';
3
+ export type { ListProps as ActionListProps } from './List';
4
+ export type { GroupProps } from './Group';
5
+ export type { ItemProps } from './Item';
6
+ export type { DescriptionProps } from './Description';
7
+ export type { LeadingVisualProps, TrailingVisualProps } from './Visuals';
8
+ /**
9
+ * Collection of list-related components.
10
+ */
11
+ export declare const ActionList: import("@radix-ui/react-polymorphic").ForwardRefComponent<"ul", import("./List").ListProps> & {
12
+ /** Collects related `Items` in an `ActionList`. */
13
+ Group: import("react").FC<import("./Group").GroupProps>;
14
+ /** An actionable or selectable `Item` with an optional icon and description. */
15
+ Item: import("@radix-ui/react-polymorphic").ForwardRefComponent<"li", import("./Item").ItemProps>;
16
+ /** Visually separates `Item`s or `Group`s in an `ActionList`. */
17
+ Divider: typeof Divider;
18
+ Description: import("react").FC<import("./Description").DescriptionProps>;
19
+ LeadingVisual: import("react").FC<import("../sx").SxProp & {
20
+ children: import("react").ReactNode;
21
+ }>;
22
+ TrailingVisual: import("react").FC<import("../sx").SxProp & {
23
+ children: import("react").ReactNode;
24
+ }>;
25
+ };
@@ -0,0 +1,23 @@
1
+ import { List } from './List';
2
+ import { Group } from './Group';
3
+ import { Item } from './Item';
4
+ import { Divider } from './Divider';
5
+ import { Description } from './Description';
6
+ import { LeadingVisual, TrailingVisual } from './Visuals';
7
+
8
+ /**
9
+ * Collection of list-related components.
10
+ */
11
+ export const ActionList = Object.assign(List, {
12
+ /** Collects related `Items` in an `ActionList`. */
13
+ Group,
14
+
15
+ /** An actionable or selectable `Item` with an optional icon and description. */
16
+ Item,
17
+
18
+ /** Visually separates `Item`s or `Group`s in an `ActionList`. */
19
+ Divider,
20
+ Description,
21
+ LeadingVisual,
22
+ TrailingVisual
23
+ });
@@ -26,8 +26,6 @@ interface AnchoredOverlayPropsWithoutAnchor {
26
26
  */
27
27
  anchorRef: React.RefObject<HTMLElement>;
28
28
  }
29
- export declare type OverlayOpenGesture = 'anchor-click' | 'anchor-key-press';
30
- export declare type OverlayCloseGesture = 'anchor-click' | 'click-outside' | 'escape';
31
29
  export declare type AnchoredOverlayWrapperAnchorProps = Partial<AnchoredOverlayPropsWithAnchor> | AnchoredOverlayPropsWithoutAnchor;
32
30
  interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'> {
33
31
  /**
@@ -37,11 +35,11 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
37
35
  /**
38
36
  * A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
39
37
  */
40
- onOpen?: (gesture: OverlayOpenGesture) => unknown;
38
+ onOpen?: (gesture: 'anchor-click' | 'anchor-key-press') => unknown;
41
39
  /**
42
40
  * A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
43
41
  */
44
- onClose?: (gesture: OverlayCloseGesture) => unknown;
42
+ onClose?: (gesture: 'anchor-click' | 'click-outside' | 'escape') => unknown;
45
43
  /**
46
44
  * Props to be spread on the internal `Overlay` component.
47
45
  */