@primer/components 0.0.0-20211040541 → 0.0.0-2021104151625

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 (158) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/dist/browser.esm.js +473 -474
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +97 -98
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Description.d.ts +12 -0
  7. package/lib/ActionList2/Description.js +53 -0
  8. package/lib/ActionList2/Divider.d.ts +5 -0
  9. package/lib/ActionList2/Divider.js +35 -0
  10. package/lib/ActionList2/Group.d.ts +11 -0
  11. package/lib/ActionList2/Group.js +57 -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 +67 -0
  15. package/lib/ActionList2/Item.js +221 -0
  16. package/lib/ActionList2/LinkItem.d.ts +17 -0
  17. package/lib/ActionList2/LinkItem.js +57 -0
  18. package/lib/ActionList2/List.d.ts +26 -0
  19. package/lib/ActionList2/List.js +51 -0
  20. package/lib/ActionList2/Selection.d.ts +5 -0
  21. package/lib/ActionList2/Selection.js +70 -0
  22. package/lib/ActionList2/Visuals.d.ts +11 -0
  23. package/lib/ActionList2/Visuals.js +90 -0
  24. package/lib/ActionList2/index.d.ts +40 -0
  25. package/lib/ActionList2/index.js +47 -0
  26. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  27. package/lib/Autocomplete/Autocomplete.d.ts +28 -30
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +28 -30
  29. package/lib/Button/Button.d.ts +24 -24
  30. package/lib/Button/Button.js +1 -1
  31. package/lib/Button/ButtonClose.d.ts +43 -43
  32. package/lib/Button/ButtonDanger.d.ts +24 -24
  33. package/lib/Button/ButtonInvisible.d.ts +24 -24
  34. package/lib/Button/ButtonOutline.d.ts +24 -24
  35. package/lib/Button/ButtonPrimary.d.ts +24 -24
  36. package/lib/CircleOcticon.d.ts +40 -40
  37. package/lib/Dialog.d.ts +43 -43
  38. package/lib/Dropdown.d.ts +168 -168
  39. package/lib/DropdownMenu/DropdownButton.d.ts +44 -44
  40. package/lib/FilterList.d.ts +40 -40
  41. package/lib/Position.d.ts +4 -4
  42. package/lib/SelectMenu/SelectMenu.d.ts +237 -239
  43. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  44. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  45. package/lib/TextInputWithTokens.d.ts +28 -30
  46. package/lib/Timeline.d.ts +41 -41
  47. package/lib/Token/AvatarToken.d.ts +1 -1
  48. package/lib/Token/IssueLabelToken.d.ts +1 -1
  49. package/lib/Token/Token.d.ts +1 -1
  50. package/lib/experiments.d.ts +1 -0
  51. package/lib/experiments.js +18 -0
  52. package/lib/hooks/useResizeObserver.d.ts +1 -1
  53. package/lib/hooks/useResizeObserver.js +1 -1
  54. package/lib/sx.d.ts +2 -0
  55. package/lib/sx.js +8 -0
  56. package/lib/theme-preval.js +79 -0
  57. package/lib/utils/create-slots.d.ts +17 -0
  58. package/lib/utils/create-slots.js +105 -0
  59. package/lib/utils/testing.d.ts +13 -0
  60. package/lib/utils/use-force-update.d.ts +1 -0
  61. package/lib/utils/use-force-update.js +19 -0
  62. package/lib-esm/ActionList2/Description.d.ts +12 -0
  63. package/lib-esm/ActionList2/Description.js +37 -0
  64. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  65. package/lib-esm/ActionList2/Divider.js +23 -0
  66. package/lib-esm/ActionList2/Group.d.ts +11 -0
  67. package/lib-esm/ActionList2/Group.js +40 -0
  68. package/lib-esm/ActionList2/Header.d.ts +26 -0
  69. package/lib-esm/ActionList2/Header.js +44 -0
  70. package/lib-esm/ActionList2/Item.d.ts +67 -0
  71. package/lib-esm/ActionList2/Item.js +195 -0
  72. package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
  73. package/lib-esm/ActionList2/LinkItem.js +43 -0
  74. package/lib-esm/ActionList2/List.d.ts +26 -0
  75. package/lib-esm/ActionList2/List.js +34 -0
  76. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  77. package/lib-esm/ActionList2/Selection.js +52 -0
  78. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  79. package/lib-esm/ActionList2/Visuals.js +68 -0
  80. package/lib-esm/ActionList2/index.d.ts +40 -0
  81. package/lib-esm/ActionList2/index.js +33 -0
  82. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  83. package/lib-esm/Autocomplete/Autocomplete.d.ts +28 -30
  84. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +28 -30
  85. package/lib-esm/Button/Button.d.ts +24 -24
  86. package/lib-esm/Button/Button.js +1 -1
  87. package/lib-esm/Button/ButtonClose.d.ts +43 -43
  88. package/lib-esm/Button/ButtonDanger.d.ts +24 -24
  89. package/lib-esm/Button/ButtonInvisible.d.ts +24 -24
  90. package/lib-esm/Button/ButtonOutline.d.ts +24 -24
  91. package/lib-esm/Button/ButtonPrimary.d.ts +24 -24
  92. package/lib-esm/CircleOcticon.d.ts +40 -40
  93. package/lib-esm/Dialog.d.ts +43 -43
  94. package/lib-esm/Dropdown.d.ts +168 -168
  95. package/lib-esm/DropdownMenu/DropdownButton.d.ts +44 -44
  96. package/lib-esm/FilterList.d.ts +40 -40
  97. package/lib-esm/Position.d.ts +4 -4
  98. package/lib-esm/SelectMenu/SelectMenu.d.ts +237 -239
  99. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  100. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  101. package/lib-esm/TextInputWithTokens.d.ts +28 -30
  102. package/lib-esm/Timeline.d.ts +41 -41
  103. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  104. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  105. package/lib-esm/Token/Token.d.ts +1 -1
  106. package/lib-esm/experiments.d.ts +1 -0
  107. package/lib-esm/experiments.js +2 -0
  108. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  109. package/lib-esm/hooks/useResizeObserver.js +1 -1
  110. package/lib-esm/sx.d.ts +2 -0
  111. package/lib-esm/sx.js +3 -1
  112. package/lib-esm/theme-preval.js +79 -0
  113. package/lib-esm/utils/create-slots.d.ts +17 -0
  114. package/lib-esm/utils/create-slots.js +84 -0
  115. package/lib-esm/utils/testing.d.ts +13 -0
  116. package/lib-esm/utils/use-force-update.d.ts +1 -0
  117. package/lib-esm/utils/use-force-update.js +6 -0
  118. package/package.json +10 -9
  119. package/lib/DatePicker/DatePicker.d.ts +0 -52
  120. package/lib/DatePicker/DatePicker.js +0 -109
  121. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  122. package/lib/DatePicker/DatePickerAnchor.js +0 -202
  123. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  124. package/lib/DatePicker/DatePickerOverlay.js +0 -55
  125. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  126. package/lib/DatePicker/DatePickerPanel.js +0 -363
  127. package/lib/DatePicker/Day.d.ts +0 -15
  128. package/lib/DatePicker/Day.js +0 -206
  129. package/lib/DatePicker/Month.d.ts +0 -8
  130. package/lib/DatePicker/Month.js +0 -122
  131. package/lib/DatePicker/dateParser.d.ts +0 -12
  132. package/lib/DatePicker/dateParser.js +0 -192
  133. package/lib/DatePicker/index.d.ts +0 -2
  134. package/lib/DatePicker/index.js +0 -13
  135. package/lib/DatePicker/useDatePicker.d.ts +0 -107
  136. package/lib/DatePicker/useDatePicker.js +0 -558
  137. package/lib/hooks/useDebounce.d.ts +0 -2
  138. package/lib/hooks/useDebounce.js +0 -24
  139. package/lib-esm/DatePicker/DatePicker.d.ts +0 -52
  140. package/lib-esm/DatePicker/DatePicker.js +0 -92
  141. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  142. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -174
  143. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  144. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -40
  145. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  146. package/lib-esm/DatePicker/DatePickerPanel.js +0 -332
  147. package/lib-esm/DatePicker/Day.d.ts +0 -15
  148. package/lib-esm/DatePicker/Day.js +0 -182
  149. package/lib-esm/DatePicker/Month.d.ts +0 -8
  150. package/lib-esm/DatePicker/Month.js +0 -98
  151. package/lib-esm/DatePicker/dateParser.d.ts +0 -12
  152. package/lib-esm/DatePicker/dateParser.js +0 -178
  153. package/lib-esm/DatePicker/index.d.ts +0 -2
  154. package/lib-esm/DatePicker/index.js +0 -1
  155. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -107
  156. package/lib-esm/DatePicker/useDatePicker.js +0 -523
  157. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  158. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -0,0 +1,195 @@
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 { useTheme } from '../ThemeProvider';
6
+ import Box from '../Box';
7
+ import { merge } from '../sx';
8
+ import createSlots from '../utils/create-slots';
9
+ import { ListContext } from './List';
10
+ import { Selection } from './Selection';
11
+ export const getVariantStyles = (variant, disabled) => {
12
+ if (disabled) {
13
+ return {
14
+ color: 'fg.muted',
15
+ iconColor: 'fg.muted',
16
+ annotationColor: 'fg.muted'
17
+ };
18
+ }
19
+
20
+ switch (variant) {
21
+ case 'danger':
22
+ return {
23
+ color: 'danger.fg',
24
+ iconColor: 'danger.fg',
25
+ annotationColor: 'fg.muted',
26
+ hoverColor: 'actionListItem.danger.hoverText'
27
+ };
28
+
29
+ default:
30
+ return {
31
+ color: 'fg.default',
32
+ iconColor: 'fg.muted',
33
+ annotationColor: 'fg.muted',
34
+ hoverColor: 'fg.default',
35
+ selectedBg: 'actionListItem.default.selectedBg'
36
+ };
37
+ }
38
+ };
39
+ const {
40
+ Slots,
41
+ Slot
42
+ } = createSlots(['LeadingVisual', 'InlineDescription', 'BlockDescription', 'TrailingVisual']);
43
+ export { Slot };
44
+ export const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
45
+
46
+ export const Item = /*#__PURE__*/React.forwardRef(({
47
+ variant = 'default',
48
+ disabled = false,
49
+ selected = undefined,
50
+ onSelect = () => null,
51
+ sx = {},
52
+ _PrivateItemWrapper = ({
53
+ children
54
+ }) => /*#__PURE__*/React.createElement(React.Fragment, null, children),
55
+ ...props
56
+ }, forwardedRef) => {
57
+ const {
58
+ variant: listVariant,
59
+ showDividers
60
+ } = React.useContext(ListContext);
61
+ const {
62
+ theme
63
+ } = useTheme();
64
+ const styles = {
65
+ display: 'flex',
66
+ paddingX: 2,
67
+ fontSize: 1,
68
+ paddingY: '6px',
69
+ // custom value off the scale
70
+ lineHeight: TEXT_ROW_HEIGHT,
71
+ marginX: listVariant === 'inset' ? 2 : 0,
72
+ minHeight: 5,
73
+ borderRadius: 2,
74
+ transition: 'background 33.333ms linear',
75
+ color: getVariantStyles(variant, disabled).color,
76
+ textDecoration: 'none',
77
+ // for as="a"
78
+ '&[aria-selected=true]': {
79
+ backgroundColor: getVariantStyles(variant, disabled).selectedBg
80
+ },
81
+ ':not([aria-disabled])': {
82
+ cursor: 'pointer'
83
+ },
84
+ '@media (hover: hover) and (pointer: fine)': {
85
+ ':hover:not([aria-disabled])': {
86
+ backgroundColor: `actionListItem.${variant}.hoverBg`,
87
+ color: getVariantStyles(variant, disabled).hoverColor
88
+ },
89
+ ':focus:not([aria-disabled])': {
90
+ backgroundColor: `actionListItem.${variant}.activeBg`,
91
+ color: getVariantStyles(variant, disabled).hoverColor,
92
+ outline: 'none'
93
+ }
94
+ },
95
+
96
+ /** Divider styles */
97
+ '[data-component="ActionList.Item--DividerContainer"]': {
98
+ position: 'relative'
99
+ },
100
+ '[data-component="ActionList.Item--DividerContainer"]::before': {
101
+ content: '" "',
102
+ display: 'block',
103
+ position: 'absolute',
104
+ width: '100%',
105
+ top: '-7px',
106
+ border: '0 solid',
107
+ borderTopWidth: showDividers ? `1px` : '0',
108
+ borderColor: 'var(--divider-color, transparent)'
109
+ },
110
+ // show between 2 items
111
+ ':not(:first-of-type):not([aria-selected=true])': {
112
+ '--divider-color': theme === null || theme === void 0 ? void 0 : theme.colors.actionListItem.inlineDivider
113
+ },
114
+ // hide divider after dividers & group header, with higher importance!
115
+ '[data-component="ActionList.Divider"] + &': {
116
+ '--divider-color': 'transparent !important'
117
+ },
118
+ // hide border on current and previous item
119
+ '&:hover:not([aria-disabled]), &:focus:not([aria-disabled])': {
120
+ '--divider-color': 'transparent'
121
+ },
122
+ '&:hover:not([aria-disabled]) + &, &:focus:not([aria-disabled]) + &': {
123
+ '--divider-color': 'transparent'
124
+ },
125
+ // hide border around selected item
126
+ '&[aria-selected=true] + &': {
127
+ '--divider-color': 'transparent'
128
+ }
129
+ };
130
+ const clickHandler = React.useCallback(event => {
131
+ if (disabled) return;
132
+ if (!event.defaultPrevented) onSelect(event);
133
+ }, [onSelect, disabled]);
134
+ const labelId = useSSRSafeId();
135
+ const inlineDescriptionId = useSSRSafeId();
136
+ const blockDescriptionId = useSSRSafeId();
137
+ return /*#__PURE__*/React.createElement(Slots, {
138
+ context: {
139
+ variant,
140
+ disabled,
141
+ inlineDescriptionId,
142
+ blockDescriptionId
143
+ }
144
+ }, slots => /*#__PURE__*/React.createElement(Box, _extends({
145
+ as: "li",
146
+ ref: forwardedRef,
147
+ sx: merge(styles, sx),
148
+ onClick: clickHandler,
149
+ "aria-selected": selected,
150
+ "aria-disabled": disabled ? true : undefined,
151
+ tabIndex: disabled ? undefined : -1,
152
+ "aria-labelledby": labelId,
153
+ "aria-describedby": [slots.InlineDescription && inlineDescriptionId, slots.BlockDescription && blockDescriptionId].filter(Boolean).join(' ')
154
+ }, props), /*#__PURE__*/React.createElement(_PrivateItemWrapper, null, /*#__PURE__*/React.createElement(Selection, {
155
+ selected: selected,
156
+ disabled: disabled
157
+ }), slots.LeadingVisual, /*#__PURE__*/React.createElement(Box, {
158
+ "data-component": "ActionList.Item--DividerContainer",
159
+ sx: {
160
+ display: 'flex',
161
+ flexDirection: 'column',
162
+ flexGrow: 1,
163
+ minWidth: 0
164
+ }
165
+ }, /*#__PURE__*/React.createElement(ConditionalBox, {
166
+ if: Boolean(slots.TrailingVisual),
167
+ sx: {
168
+ display: 'flex',
169
+ flexGrow: 1
170
+ }
171
+ }, /*#__PURE__*/React.createElement(ConditionalBox, {
172
+ if: Boolean(slots.InlineDescription),
173
+ sx: {
174
+ display: 'flex',
175
+ flexGrow: 1,
176
+ alignItems: 'baseline',
177
+ minWidth: 0
178
+ }
179
+ }, /*#__PURE__*/React.createElement(Box, {
180
+ as: "span",
181
+ id: labelId,
182
+ sx: {
183
+ flexGrow: slots.InlineDescription ? 0 : 1
184
+ }
185
+ }, props.children), slots.InlineDescription), slots.TrailingVisual), slots.BlockDescription))));
186
+ });
187
+ Item.displayName = 'ActionList.Item';
188
+
189
+ const ConditionalBox = props => {
190
+ const {
191
+ if: condition,
192
+ ...rest
193
+ } = props;
194
+ if (condition) return /*#__PURE__*/React.createElement(Box, rest, props.children);else return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
195
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
+ import { ItemProps } from './Item';
4
+ declare type LinkProps = {
5
+ download?: string;
6
+ href?: string;
7
+ hrefLang?: string;
8
+ media?: string;
9
+ ping?: string;
10
+ rel?: string;
11
+ target?: string;
12
+ type?: string;
13
+ referrerPolicy?: React.AnchorHTMLAttributes<HTMLAnchorElement>['referrerPolicy'];
14
+ };
15
+ declare type LinkItemProps = Pick<ItemProps, 'children' | 'sx'> & LinkProps;
16
+ export declare const LinkItem: PolymorphicForwardRefComponent<"a", LinkItemProps>;
17
+ export {};
@@ -0,0 +1,43 @@
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 Link from '../Link';
5
+ import { merge } from '../sx';
6
+ import { Item } from './Item'; // adopted from React.AnchorHTMLAttributes
7
+
8
+ export const LinkItem = /*#__PURE__*/React.forwardRef(({
9
+ sx = {},
10
+ as: Component,
11
+ ...props
12
+ }, forwardedRef) => {
13
+ const styles = {
14
+ // occupy full size of Item
15
+ paddingX: 2,
16
+ paddingY: '6px',
17
+ // custom value off the scale
18
+ display: 'flex',
19
+ flexGrow: 1,
20
+ // full width
21
+ borderRadius: 2,
22
+ // inherit Item styles
23
+ color: 'inherit',
24
+ '&:hover': {
25
+ color: 'inherit',
26
+ textDecoration: 'none'
27
+ }
28
+ };
29
+ return /*#__PURE__*/React.createElement(Item, {
30
+ sx: {
31
+ paddingY: 0,
32
+ paddingX: 0
33
+ },
34
+ _PrivateItemWrapper: ({
35
+ children
36
+ }) => /*#__PURE__*/React.createElement(Link, _extends({
37
+ as: Component,
38
+ sx: merge(styles, sx)
39
+ }, props, {
40
+ ref: forwardedRef
41
+ }), children)
42
+ }, props.children);
43
+ });
@@ -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,34 @@
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
+ export const ListContext = /*#__PURE__*/React.createContext({});
7
+ export const List = /*#__PURE__*/React.forwardRef(({
8
+ variant = 'inset',
9
+ selectionVariant,
10
+ showDividers = false,
11
+ sx = {},
12
+ ...props
13
+ }, forwardedRef) => {
14
+ const styles = {
15
+ margin: 0,
16
+ paddingInlineStart: 0,
17
+ // reset ul styles
18
+ paddingY: variant === 'inset' ? 2 : 0
19
+ };
20
+ return /*#__PURE__*/React.createElement(Box, _extends({
21
+ as: "ul",
22
+ sx: merge(styles, sx),
23
+ "aria-multiselectable": selectionVariant === 'multiple' ? true : undefined
24
+ }, props, {
25
+ ref: forwardedRef
26
+ }), /*#__PURE__*/React.createElement(ListContext.Provider, {
27
+ value: {
28
+ variant,
29
+ selectionVariant,
30
+ showDividers
31
+ }
32
+ }, props.children));
33
+ });
34
+ 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,52 @@
1
+ import React from 'react';
2
+ import { CheckIcon } from '@primer/octicons-react';
3
+ import { ListContext } from './List';
4
+ import { GroupContext } from './Group';
5
+ import { LeadingVisualContainer } from './Visuals';
6
+ export const Selection = ({
7
+ selected,
8
+ disabled
9
+ }) => {
10
+ const {
11
+ selectionVariant: listSelectionVariant
12
+ } = React.useContext(ListContext);
13
+ const {
14
+ selectionVariant: groupSelectionVariant
15
+ } = React.useContext(GroupContext);
16
+ /** selectionVariant in Group can override the selectionVariant in List root */
17
+
18
+ const selectionVariant = typeof groupSelectionVariant !== 'undefined' ? groupSelectionVariant : listSelectionVariant; // if selectionVariant is not set on List, don't show selection
19
+
20
+ if (!selectionVariant) {
21
+ // to avoid confusion, fail loudly instead of silently ignoring
22
+ if (selected) throw new Error('For Item to be selected, ActionList or ActionList.Group needs to have a selectionVariant defined');
23
+ return null;
24
+ }
25
+
26
+ if (selectionVariant === 'single') {
27
+ return /*#__PURE__*/React.createElement(LeadingVisualContainer, null, selected && /*#__PURE__*/React.createElement(CheckIcon, null));
28
+ }
29
+ /**
30
+ * selectionVariant is multiple
31
+ * readOnly is required because we are doing a one-way bind to `checked`
32
+ * aria-readonly="false" tells screen that they can still interact with the checkbox
33
+ */
34
+
35
+
36
+ return /*#__PURE__*/React.createElement(LeadingVisualContainer, {
37
+ sx: {
38
+ input: {
39
+ margin: 0,
40
+ pointerEvents: 'none'
41
+ }
42
+ }
43
+ }, /*#__PURE__*/React.createElement("input", {
44
+ type: "checkbox",
45
+ checked: selected,
46
+ disabled: disabled,
47
+ tabIndex: -1,
48
+ readOnly: true,
49
+ "aria-readonly": "false"
50
+ }));
51
+ };
52
+ 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, TEXT_ROW_HEIGHT } 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: TEXT_ROW_HEIGHT,
16
+ // match height of text row
17
+ minWidth: get('space.3'),
18
+ maxWidth: TEXT_ROW_HEIGHT,
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,40 @@
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` */
15
+ Item: import("@radix-ui/react-polymorphic").ForwardRefComponent<"li", import("./Item").ItemProps>;
16
+ /** A `Item` that renders a full-size anchor inside ListItem */
17
+ LinkItem: import("@radix-ui/react-polymorphic").ForwardRefComponent<"a", Pick<import("./Item").ItemProps, "children" | "sx"> & {
18
+ download?: string | undefined;
19
+ href?: string | undefined;
20
+ hrefLang?: string | undefined;
21
+ media?: string | undefined;
22
+ ping?: string | undefined;
23
+ rel?: string | undefined;
24
+ target?: string | undefined;
25
+ type?: string | undefined;
26
+ referrerPolicy?: import("react").HTMLAttributeReferrerPolicy | undefined;
27
+ }>;
28
+ /** Visually separates `Item`s or `Group`s in an `ActionList`. */
29
+ Divider: typeof Divider;
30
+ /** Secondary text which provides additional information about an `Item`. */
31
+ Description: import("react").FC<import("./Description").DescriptionProps>;
32
+ /** Icon (or similar) positioned before `Item` text. */
33
+ LeadingVisual: import("react").FC<import("../sx").SxProp & {
34
+ children: import("react").ReactNode;
35
+ }>;
36
+ /** Icon (or similar) positioned after `Item` text. */
37
+ TrailingVisual: import("react").FC<import("../sx").SxProp & {
38
+ children: import("react").ReactNode;
39
+ }>;
40
+ };
@@ -0,0 +1,33 @@
1
+ import { List } from './List';
2
+ import { Group } from './Group';
3
+ import { Item } from './Item';
4
+ import { LinkItem } from './LinkItem';
5
+ import { Divider } from './Divider';
6
+ import { Description } from './Description';
7
+ import { LeadingVisual, TrailingVisual } from './Visuals';
8
+
9
+ /**
10
+ * Collection of list-related components.
11
+ */
12
+ export const ActionList = Object.assign(List, {
13
+ /** Collects related `Items` in an `ActionList`. */
14
+ Group,
15
+
16
+ /** An actionable or selectable `Item` */
17
+ Item,
18
+
19
+ /** A `Item` that renders a full-size anchor inside ListItem */
20
+ LinkItem,
21
+
22
+ /** Visually separates `Item`s or `Group`s in an `ActionList`. */
23
+ Divider,
24
+
25
+ /** Secondary text which provides additional information about an `Item`. */
26
+ Description,
27
+
28
+ /** Icon (or similar) positioned before `Item` text. */
29
+ LeadingVisual,
30
+
31
+ /** Icon (or similar) positioned after `Item` text. */
32
+ TrailingVisual
33
+ });
@@ -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
  */