@primer/components 0.0.0-20219283497 → 0.0.0-2021929153151

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 (162) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/browser.esm.js +447 -440
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +446 -439
  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 +11 -0
  11. package/lib/ActionList2/Group.js +55 -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 +73 -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 +28 -0
  25. package/lib/ActionList2/index.js +42 -0
  26. package/lib/ActionMenu.js +2 -2
  27. package/lib/Autocomplete/Autocomplete.d.ts +30 -30
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +30 -30
  29. package/lib/Button/Button.d.ts +30 -30
  30. package/lib/Button/ButtonBase.d.ts +1 -1
  31. package/lib/Button/ButtonClose.d.ts +35 -35
  32. package/lib/Button/ButtonDanger.d.ts +30 -30
  33. package/lib/Button/ButtonInvisible.d.ts +30 -30
  34. package/lib/Button/ButtonOutline.d.ts +30 -30
  35. package/lib/Button/ButtonPrimary.d.ts +30 -30
  36. package/lib/Button/ButtonStyles.js +1 -1
  37. package/lib/CircleBadge.d.ts +2 -2
  38. package/lib/CircleOcticon.d.ts +38 -38
  39. package/lib/Dialog/Dialog.d.ts +4 -4
  40. package/lib/Dialog/Dialog.js +22 -12
  41. package/lib/Dialog.d.ts +41 -41
  42. package/lib/Dropdown.d.ts +215 -137
  43. package/lib/Dropdown.js +5 -6
  44. package/lib/DropdownMenu/DropdownButton.d.ts +37 -37
  45. package/lib/FilterList.d.ts +30 -30
  46. package/lib/Flash.d.ts +1 -1
  47. package/lib/Label.d.ts +1 -1
  48. package/lib/Position.d.ts +4 -4
  49. package/lib/SelectMenu/SelectMenu.d.ts +187 -187
  50. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  51. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  52. package/lib/TextInputWithTokens.d.ts +34 -30
  53. package/lib/TextInputWithTokens.js +102 -29
  54. package/lib/Timeline.d.ts +39 -39
  55. package/lib/Token/AvatarToken.d.ts +1 -1
  56. package/lib/Token/IssueLabelToken.d.ts +1 -1
  57. package/lib/Token/Token.d.ts +1 -1
  58. package/lib/Token/Token.js +13 -2
  59. package/lib/Token/TokenBase.js +0 -4
  60. package/lib/Token/_RemoveTokenButton.js +15 -2
  61. package/lib/_TextInputWrapper.js +1 -1
  62. package/lib/constants.js +1 -3
  63. package/lib/experiments.d.ts +1 -0
  64. package/lib/experiments.js +18 -0
  65. package/lib/index.d.ts +0 -2
  66. package/lib/index.js +0 -8
  67. package/lib/sx.d.ts +10 -2
  68. package/lib/sx.js +8 -0
  69. package/lib/theme.d.ts +78 -0
  70. package/lib/theme.js +3 -1
  71. package/lib/utils/create-slots.d.ts +17 -0
  72. package/lib/utils/create-slots.js +105 -0
  73. package/lib/utils/testing.d.ts +1 -1
  74. package/lib/utils/types/KeyPaths.d.ts +3 -0
  75. package/lib/utils/types/KeyPaths.js +1 -0
  76. package/lib/utils/use-force-update.d.ts +1 -0
  77. package/lib/utils/use-force-update.js +19 -0
  78. package/lib-esm/ActionList2/Description.d.ts +6 -0
  79. package/lib-esm/ActionList2/Description.js +37 -0
  80. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  81. package/lib-esm/ActionList2/Divider.js +21 -0
  82. package/lib-esm/ActionList2/Group.d.ts +11 -0
  83. package/lib-esm/ActionList2/Group.js +38 -0
  84. package/lib-esm/ActionList2/Header.d.ts +26 -0
  85. package/lib-esm/ActionList2/Header.js +45 -0
  86. package/lib-esm/ActionList2/Item.d.ts +48 -0
  87. package/lib-esm/ActionList2/Item.js +176 -0
  88. package/lib-esm/ActionList2/List.d.ts +26 -0
  89. package/lib-esm/ActionList2/List.js +38 -0
  90. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  91. package/lib-esm/ActionList2/Selection.js +55 -0
  92. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  93. package/lib-esm/ActionList2/Visuals.js +68 -0
  94. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  95. package/lib-esm/ActionList2/hacks.js +30 -0
  96. package/lib-esm/ActionList2/index.d.ts +28 -0
  97. package/lib-esm/ActionList2/index.js +29 -0
  98. package/lib-esm/ActionMenu.js +2 -2
  99. package/lib-esm/Autocomplete/Autocomplete.d.ts +30 -30
  100. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +30 -30
  101. package/lib-esm/Button/Button.d.ts +30 -30
  102. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  103. package/lib-esm/Button/ButtonClose.d.ts +35 -35
  104. package/lib-esm/Button/ButtonDanger.d.ts +30 -30
  105. package/lib-esm/Button/ButtonInvisible.d.ts +30 -30
  106. package/lib-esm/Button/ButtonOutline.d.ts +30 -30
  107. package/lib-esm/Button/ButtonPrimary.d.ts +30 -30
  108. package/lib-esm/Button/ButtonStyles.js +1 -1
  109. package/lib-esm/CircleBadge.d.ts +2 -2
  110. package/lib-esm/CircleOcticon.d.ts +38 -38
  111. package/lib-esm/Dialog/Dialog.d.ts +4 -4
  112. package/lib-esm/Dialog/Dialog.js +21 -12
  113. package/lib-esm/Dialog.d.ts +41 -41
  114. package/lib-esm/Dropdown.d.ts +215 -137
  115. package/lib-esm/Dropdown.js +3 -4
  116. package/lib-esm/DropdownMenu/DropdownButton.d.ts +37 -37
  117. package/lib-esm/FilterList.d.ts +30 -30
  118. package/lib-esm/Flash.d.ts +1 -1
  119. package/lib-esm/Label.d.ts +1 -1
  120. package/lib-esm/Position.d.ts +4 -4
  121. package/lib-esm/SelectMenu/SelectMenu.d.ts +187 -187
  122. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  123. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  124. package/lib-esm/TextInputWithTokens.d.ts +34 -30
  125. package/lib-esm/TextInputWithTokens.js +101 -30
  126. package/lib-esm/Timeline.d.ts +39 -39
  127. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  128. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  129. package/lib-esm/Token/Token.d.ts +1 -1
  130. package/lib-esm/Token/Token.js +13 -2
  131. package/lib-esm/Token/TokenBase.js +0 -4
  132. package/lib-esm/Token/_RemoveTokenButton.js +11 -2
  133. package/lib-esm/_TextInputWrapper.js +1 -1
  134. package/lib-esm/constants.js +1 -3
  135. package/lib-esm/experiments.d.ts +1 -0
  136. package/lib-esm/experiments.js +2 -0
  137. package/lib-esm/index.d.ts +0 -2
  138. package/lib-esm/index.js +0 -1
  139. package/lib-esm/sx.d.ts +10 -2
  140. package/lib-esm/sx.js +3 -1
  141. package/lib-esm/theme.d.ts +78 -0
  142. package/lib-esm/theme.js +2 -1
  143. package/lib-esm/utils/create-slots.d.ts +17 -0
  144. package/lib-esm/utils/create-slots.js +84 -0
  145. package/lib-esm/utils/testing.d.ts +1 -1
  146. package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
  147. package/lib-esm/utils/types/KeyPaths.js +1 -0
  148. package/lib-esm/utils/use-force-update.d.ts +1 -0
  149. package/lib-esm/utils/use-force-update.js +6 -0
  150. package/package.json +4 -1
  151. package/lib/NewButton/button.d.ts +0 -581
  152. package/lib/NewButton/button.js +0 -297
  153. package/lib/NewButton/counter.d.ts +0 -6
  154. package/lib/NewButton/counter.js +0 -33
  155. package/lib/NewButton/index.d.ts +0 -4
  156. package/lib/NewButton/index.js +0 -21
  157. package/lib-esm/NewButton/button.d.ts +0 -581
  158. package/lib-esm/NewButton/button.js +0 -273
  159. package/lib-esm/NewButton/counter.d.ts +0 -6
  160. package/lib-esm/NewButton/counter.js +0 -21
  161. package/lib-esm/NewButton/index.d.ts +0 -4
  162. package/lib-esm/NewButton/index.js +0 -3
package/lib/theme.d.ts CHANGED
@@ -1,2 +1,80 @@
1
1
  import { theme } from './theme-preval';
2
+ import { KeyPaths } from './utils/types/KeyPaths';
2
3
  export default theme;
4
+ declare type ThemeColors = {
5
+ fg: {
6
+ default: string;
7
+ muted: string;
8
+ subtle: string;
9
+ onEmphasis: string;
10
+ };
11
+ canvas: {
12
+ default: string;
13
+ overlay: string;
14
+ inset: string;
15
+ subtle: string;
16
+ };
17
+ border: {
18
+ default: string;
19
+ muted: string;
20
+ subtle: string;
21
+ };
22
+ neutral: {
23
+ emphasisPlus: string;
24
+ emphasis: string;
25
+ muted: string;
26
+ subtle: string;
27
+ };
28
+ accent: {
29
+ fg: string;
30
+ emphasis: string;
31
+ muted: string;
32
+ subtle: string;
33
+ };
34
+ success: {
35
+ fg: string;
36
+ emphasis: string;
37
+ muted: string;
38
+ subtle: string;
39
+ };
40
+ attention: {
41
+ fg: string;
42
+ emphasis: string;
43
+ muted: string;
44
+ subtle: string;
45
+ };
46
+ severe: {
47
+ fg: string;
48
+ emphasis: string;
49
+ muted: string;
50
+ subtle: string;
51
+ };
52
+ danger: {
53
+ fg: string;
54
+ emphasis: string;
55
+ muted: string;
56
+ subtle: string;
57
+ };
58
+ done: {
59
+ fg: string;
60
+ emphasis: string;
61
+ muted: string;
62
+ subtle: string;
63
+ };
64
+ sponsors: {
65
+ fg: string;
66
+ emphasis: string;
67
+ muted: string;
68
+ subtle: string;
69
+ };
70
+ };
71
+ declare type ThemeShadows = {
72
+ shadow: {
73
+ small: string;
74
+ medium: string;
75
+ large: string;
76
+ extraLarge: string;
77
+ };
78
+ };
79
+ export declare type ThemeColorPaths = KeyPaths<ThemeColors>;
80
+ export declare type ThemeShadowPaths = KeyPaths<ThemeShadows>;
package/lib/theme.js CHANGED
@@ -7,5 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _themePreval = require("./theme-preval");
9
9
 
10
- var _default = _themePreval.theme;
10
+ var _default = _themePreval.theme; // NOTE: for now, ThemeColors and ThemeShadows are handcrafted types. It would be nice if these
11
+ // were exports from primitives (or a different shape but derived from those exports).
12
+
11
13
  exports.default = _default;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ /** createSlots is a factory that can create a
3
+ * typesafe Slots + Slot pair to use in a component definition
4
+ * For example: ActionList.Item uses createSlots to get a Slots wrapper
5
+ * + Slot component that is used by LeadingVisual, Description
6
+ */
7
+ declare const createSlots: <SlotNames extends string>(slotNames: SlotNames[]) => {
8
+ Slots: React.FC<{
9
+ context: Record<string, unknown>;
10
+ children: (slots: { [key in SlotNames]?: React.ReactNode; }) => React.ReactNode;
11
+ }>;
12
+ Slot: React.FC<{
13
+ name: SlotNames;
14
+ children: React.ReactNode | ((context: Record<string, unknown>) => React.ReactNode);
15
+ }>;
16
+ };
17
+ export default createSlots;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _useForceUpdate = require("./use-force-update");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /** createSlots is a factory that can create a
15
+ * typesafe Slots + Slot pair to use in a component definition
16
+ * For example: ActionList.Item uses createSlots to get a Slots wrapper
17
+ * + Slot component that is used by LeadingVisual, Description
18
+ */
19
+ const createSlots = slotNames => {
20
+ const SlotsContext = /*#__PURE__*/_react.default.createContext({
21
+ registerSlot: () => null,
22
+ unregisterSlot: () => null,
23
+ context: {}
24
+ });
25
+ /** Slots uses a Double render strategy inspired by [reach-ui/descendants](https://github.com/reach/reach-ui/tree/develop/packages/descendants)
26
+ * Slot registers themself with the Slots parent.
27
+ * When all the children have mounted = registered themselves in slot,
28
+ * we re-render the parent component to render with slots
29
+ */
30
+
31
+
32
+ const Slots = ({
33
+ context,
34
+ children
35
+ }) => {
36
+ // initialise slots
37
+ const slotsDefinition = {};
38
+ slotNames.map(name => slotsDefinition[name] = null);
39
+
40
+ const slotsRef = _react.default.useRef(slotsDefinition);
41
+
42
+ const rerenderWithSlots = (0, _useForceUpdate.useForceUpdate)();
43
+
44
+ const [isMounted, setIsMounted] = _react.default.useState(false); // fires after all the effects in children
45
+
46
+
47
+ _react.default.useEffect(() => {
48
+ rerenderWithSlots();
49
+ setIsMounted(true);
50
+ }, [rerenderWithSlots]);
51
+
52
+ const registerSlot = _react.default.useCallback((name, contents) => {
53
+ slotsRef.current[name] = contents; // don't render until the component mounts = all slots are registered
54
+
55
+ if (isMounted) rerenderWithSlots();
56
+ }, [isMounted, rerenderWithSlots]); // Slot can be removed from the tree as well,
57
+ // we need to unregister them from the slot
58
+
59
+
60
+ const unregisterSlot = _react.default.useCallback(name => {
61
+ slotsRef.current[name] = null;
62
+ rerenderWithSlots();
63
+ }, [rerenderWithSlots]);
64
+ /**
65
+ * Slots uses a render prop API so abstract the
66
+ * implementation detail of using a context provider.
67
+ */
68
+
69
+
70
+ const slots = slotsRef.current;
71
+ return /*#__PURE__*/_react.default.createElement(SlotsContext.Provider, {
72
+ value: {
73
+ registerSlot,
74
+ unregisterSlot,
75
+ context
76
+ }
77
+ }, children(slots));
78
+ };
79
+
80
+ const Slot = ({
81
+ name,
82
+ children
83
+ }) => {
84
+ const {
85
+ registerSlot,
86
+ unregisterSlot,
87
+ context
88
+ } = _react.default.useContext(SlotsContext);
89
+
90
+ _react.default.useEffect(() => {
91
+ registerSlot(name, typeof children === 'function' ? children(context) : children);
92
+ return () => unregisterSlot(name);
93
+ }, [name, children, registerSlot, unregisterSlot, context]);
94
+
95
+ return null;
96
+ };
97
+
98
+ return {
99
+ Slots,
100
+ Slot
101
+ };
102
+ };
103
+
104
+ var _default = createSlots;
105
+ exports.default = _default;
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
53
53
  xlarge: string;
54
54
  };
55
55
  space: string[];
56
- colorSchemes: Record<"dark" | "light" | "light_protanopia" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
56
+ colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
57
57
  canvasDefaultTransparent: string;
58
58
  marketingIcon: {
59
59
  primary: string;
@@ -0,0 +1,3 @@
1
+ export declare type KeyPaths<O extends Record<string, unknown>> = {
2
+ [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never;
3
+ }[keyof O];
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export declare const useForceUpdate: () => () => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useForceUpdate = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ // Inspired from reach-ui: https://github.com/reach/reach-ui/blob/develop/packages/utils/src/use-force-update.ts
13
+ const useForceUpdate = () => {
14
+ const [, rerender] = _react.default.useState({});
15
+
16
+ return _react.default.useCallback(() => rerender({}), []);
17
+ };
18
+
19
+ exports.useForceUpdate = useForceUpdate;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { SxProp } from '../sx';
3
+ export declare type DescriptionProps = {
4
+ variant?: 'inline' | 'block';
5
+ } & SxProp;
6
+ export declare const Description: React.FC<DescriptionProps>;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import Box from '../Box';
3
+ import { merge } from '../sx';
4
+ import Truncate from '../Truncate';
5
+ import { Slot } from './Item';
6
+ export const Description = ({
7
+ variant = 'inline',
8
+ sx = {},
9
+ ...props
10
+ }) => {
11
+ const styles = {
12
+ color: 'fg.muted',
13
+ fontSize: 0,
14
+ lineHeight: '16px',
15
+ flexGrow: 1,
16
+ flexBasis: 0,
17
+ minWidth: 0,
18
+ marginLeft: variant === 'block' ? 0 : 2
19
+ };
20
+ return /*#__PURE__*/React.createElement(Slot, {
21
+ name: variant === 'block' ? 'BlockDescription' : 'InlineDescription'
22
+ }, ({
23
+ blockDescriptionId,
24
+ inlineDescriptionId
25
+ }) => variant === 'block' ? /*#__PURE__*/React.createElement(Box, {
26
+ as: "span",
27
+ sx: merge(styles, sx),
28
+ id: blockDescriptionId
29
+ }, props.children) : /*#__PURE__*/React.createElement(Truncate, {
30
+ id: inlineDescriptionId,
31
+ sx: merge(styles, sx),
32
+ title: props.children,
33
+ inline: true,
34
+ maxWidth: "100%"
35
+ }, props.children));
36
+ };
37
+ Description.displayName = "Description";
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Visually separates `Item`s or `Group`s in an `ActionList`.
4
+ */
5
+ export declare function Divider(): JSX.Element;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import Box from '../Box';
3
+ import { get } from '../constants';
4
+
5
+ /**
6
+ * Visually separates `Item`s or `Group`s in an `ActionList`.
7
+ */
8
+ export function Divider() {
9
+ return /*#__PURE__*/React.createElement(Box, {
10
+ as: "li",
11
+ role: "separator",
12
+ sx: {
13
+ height: 1,
14
+ backgroundColor: 'border.muted',
15
+ marginTop: theme => `calc(${get('space.2')(theme)} - 1px)`,
16
+ marginBottom: 2
17
+ },
18
+ "data-component": "ActionList.Divider"
19
+ });
20
+ }
21
+ Divider.displayName = "Divider";
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { SxProp } from '../sx';
3
+ import { HeaderProps } from './Header';
4
+ import { ListProps } from './List';
5
+ export declare type GroupProps = HeaderProps & SxProp & {
6
+ selectionVariant?: ListProps['selectionVariant'] | false;
7
+ };
8
+ declare type ContextProps = Pick<GroupProps, 'selectionVariant'>;
9
+ export declare const GroupContext: React.Context<ContextProps>;
10
+ export declare const Group: React.FC<GroupProps>;
11
+ 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 { Header } from './Header';
6
+ export const GroupContext = /*#__PURE__*/React.createContext({});
7
+ export const Group = ({
8
+ title,
9
+ variant,
10
+ auxiliaryText,
11
+ selectionVariant,
12
+ sx = {},
13
+ ...props
14
+ }) => {
15
+ return /*#__PURE__*/React.createElement(Box, _extends({
16
+ as: "li",
17
+ sx: {
18
+ '&:not(:first-child)': {
19
+ marginTop: 2
20
+ },
21
+ ...sx
22
+ }
23
+ }, props), title && /*#__PURE__*/React.createElement(Header, {
24
+ title: title,
25
+ variant: variant,
26
+ auxiliaryText: auxiliaryText
27
+ }), /*#__PURE__*/React.createElement(GroupContext.Provider, {
28
+ value: {
29
+ selectionVariant
30
+ }
31
+ }, /*#__PURE__*/React.createElement(Box, {
32
+ as: "ul",
33
+ sx: {
34
+ paddingInlineStart: 0
35
+ }
36
+ }, props.children)));
37
+ };
38
+ 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
+ };