@primer/components 0.0.0-20219151705 → 0.0.0-2021915202729

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 (50) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +725 -725
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +731 -731
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/index.d.ts +0 -1
  7. package/lib/index.js +0 -8
  8. package/lib-esm/index.d.ts +0 -1
  9. package/lib-esm/index.js +0 -1
  10. package/package.json +1 -2
  11. package/lib/ActionList2/Description.d.ts +0 -5
  12. package/lib/ActionList2/Description.js +0 -55
  13. package/lib/ActionList2/Divider.d.ts +0 -8
  14. package/lib/ActionList2/Divider.js +0 -42
  15. package/lib/ActionList2/Group.d.ts +0 -8
  16. package/lib/ActionList2/Group.js +0 -39
  17. package/lib/ActionList2/Header.d.ts +0 -26
  18. package/lib/ActionList2/Header.js +0 -55
  19. package/lib/ActionList2/Item.d.ts +0 -56
  20. package/lib/ActionList2/Item.js +0 -216
  21. package/lib/ActionList2/List.d.ts +0 -18
  22. package/lib/ActionList2/List.js +0 -52
  23. package/lib/ActionList2/Selection.d.ts +0 -5
  24. package/lib/ActionList2/Selection.js +0 -67
  25. package/lib/ActionList2/Visuals.d.ts +0 -12
  26. package/lib/ActionList2/Visuals.js +0 -101
  27. package/lib/ActionList2/hacks.d.ts +0 -30
  28. package/lib/ActionList2/hacks.js +0 -38
  29. package/lib/ActionList2/index.d.ts +0 -26
  30. package/lib/ActionList2/index.js +0 -36
  31. package/lib-esm/ActionList2/Description.d.ts +0 -5
  32. package/lib-esm/ActionList2/Description.js +0 -37
  33. package/lib-esm/ActionList2/Divider.d.ts +0 -8
  34. package/lib-esm/ActionList2/Divider.js +0 -30
  35. package/lib-esm/ActionList2/Group.d.ts +0 -8
  36. package/lib-esm/ActionList2/Group.js +0 -29
  37. package/lib-esm/ActionList2/Header.d.ts +0 -26
  38. package/lib-esm/ActionList2/Header.js +0 -45
  39. package/lib-esm/ActionList2/Item.d.ts +0 -56
  40. package/lib-esm/ActionList2/Item.js +0 -211
  41. package/lib-esm/ActionList2/List.d.ts +0 -18
  42. package/lib-esm/ActionList2/List.js +0 -42
  43. package/lib-esm/ActionList2/Selection.d.ts +0 -5
  44. package/lib-esm/ActionList2/Selection.js +0 -50
  45. package/lib-esm/ActionList2/Visuals.d.ts +0 -12
  46. package/lib-esm/ActionList2/Visuals.js +0 -76
  47. package/lib-esm/ActionList2/hacks.d.ts +0 -30
  48. package/lib-esm/ActionList2/hacks.js +0 -30
  49. package/lib-esm/ActionList2/index.d.ts +0 -26
  50. package/lib-esm/ActionList2/index.js +0 -23
@@ -1,211 +0,0 @@
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
- * test suite!
5
- * id, role
6
- * text could be non-text
7
- * activeDescendantAttribute
8
- * deepmerge sx
9
- * nicer name for showDivider?
10
- * aria-label
11
- * aria-describedby
12
- * React.FC<Props> doesn't allow id?
13
- * truncate description
14
- * icon color
15
- * disabled checkbox
16
- * check height with divider
17
- *
18
- * use immediate child slot API instead of double render?
19
- * change as= li | div based on context of menu or not?
20
- * check if everyone accepts sx prop
21
- * link example outside of overlay? (details)
22
- * if one item has selected, should we give all of them selected without the need to pass prop?
23
- * move custom item themes to primitives?
24
- * padding: 8 or 6?
25
- * ActionList.Selection or ActionList.Item selected?
26
- * different size for icon and avatar, range?
27
- * minimize number of divs?
28
- * improve double render by wrapping custom children in memo
29
- * improve double render by wrapping children in memo
30
- */
31
- import React from 'react';
32
- import { useColorSchemeVar, useTheme } from '../ThemeProvider';
33
- import Box from '../Box';
34
- import { get } from '../constants';
35
- import { ListContext } from './List';
36
- import { customItemThemes } from './hacks';
37
- import { Selection } from './Selection';
38
- import isEqual from 'lodash.isequal';
39
- export const getVariantStyles = (variant, disabled) => {
40
- if (disabled) {
41
- return {
42
- color: get('colors.fg.muted'),
43
- iconColor: get('colors.fg.muted'),
44
- annotationColor: get('colors.fg.muted')
45
- };
46
- }
47
-
48
- switch (variant) {
49
- case 'danger':
50
- return {
51
- color: 'danger.fg',
52
- iconColor: 'danger.fg',
53
- annotationColor: 'fg.muted'
54
- };
55
-
56
- default:
57
- return {
58
- color: 'fg.default',
59
- iconColor: 'fg.muted',
60
- annotationColor: 'fg.muted'
61
- };
62
- }
63
- };
64
- export const ItemContext = /*#__PURE__*/React.createContext({
65
- registerSlot: () => null,
66
- deregisterSlot: () => null
67
- });
68
- export const Item = /*#__PURE__*/React.forwardRef(({
69
- variant = 'default',
70
- disabled = false,
71
- selected = undefined,
72
- showDivider = false,
73
- onAction = () => null,
74
- sx = {},
75
- ...props
76
- }, forwardedRef) => {
77
- const customItemTheme = customItemThemes[variant];
78
- const {
79
- variant: listVariant
80
- } = React.useContext(ListContext);
81
- const {
82
- theme
83
- } = useTheme(); // Double render strategy
84
- // when the effect is run for the first time,
85
- // all the children have rendered = registed themself in slot.
86
- // we re-render the Item component to re-render with filled slots.
87
-
88
- const [, rerenderWithSlots] = React.useState(0);
89
- const [isMounted, setIsMounted] = React.useState(false);
90
- React.useLayoutEffect(() => {
91
- setIsMounted(true);
92
- rerenderWithSlots(count => count + 1);
93
- }, []);
94
- const slotsRef = React.useRef({
95
- LeadingVisual: null,
96
- InlineDescription: null,
97
- BlockDescription: null,
98
- TrailingVisual: null
99
- });
100
- const slots = slotsRef.current;
101
-
102
- const registerSlot = (name, contents) => {
103
- const currentContents = slotsRef.current[name];
104
- slotsRef.current[name] = contents; // don't render until the component mounts = all slots are registered
105
-
106
- if (!isMounted) return; // only rerender if the values are different to avoid an infinite loop
107
-
108
- if (!isEqual(currentContents === null || currentContents === void 0 ? void 0 : currentContents.props, contents.props)) {
109
- rerenderWithSlots(count => count + 1);
110
- }
111
- };
112
-
113
- const deregisterSlot = name => {
114
- slotsRef.current[name] = null;
115
- rerenderWithSlots(count => count + 1);
116
- };
117
-
118
- const styles = {
119
- display: 'flex',
120
- paddingX: get('space.2'),
121
- paddingY: '6px',
122
- marginX: listVariant === 'inset' ? get('space.2') : 0,
123
- minHeight: get('space.5'),
124
- borderRadius: get('radii.2'),
125
- transition: 'background 33.333ms linear',
126
- color: getVariantStyles(variant, disabled).color,
127
- textDecoration: 'none',
128
- // for as="a"
129
- ':not(disabled)': {
130
- cursor: 'pointer'
131
- },
132
- '@media (hover: hover) and (pointer: fine)': {
133
- ':hover': {
134
- backgroundColor: useColorSchemeVar(customItemTheme.hover, 'inherit')
135
- },
136
- ':focus': {
137
- backgroundColor: useColorSchemeVar(customItemTheme.focus, 'inherit')
138
- }
139
- },
140
-
141
- /** Divider styles */
142
- '[data-component="ActionList.Item--Main"]': {
143
- position: 'relative'
144
- },
145
- '[data-component="ActionList.Item--Main"]::before': {
146
- content: '" "',
147
- display: 'block',
148
- position: 'absolute',
149
- width: '100%',
150
- top: '-7px',
151
- border: '0 solid',
152
- borderTopWidth: showDivider ? `1px` : '0',
153
- borderColor: 'var(--divider-color, transparent)'
154
- },
155
- // show between 2 items
156
- ':not(:first-of-type)': {
157
- '--divider-color': theme === null || theme === void 0 ? void 0 : theme.colors.border.muted
158
- },
159
- // hide divider after dividers & group header
160
- '[data-component="ActionList.Divider"] + &': {
161
- '--divider-color': 'transparent'
162
- },
163
- // hide border on current and previous item
164
- '&:hover, &:focus': {
165
- '--divider-color': 'transparent'
166
- },
167
- '&:hover + &, &:focus + &': {
168
- '--divider-color': 'transparent'
169
- },
170
- ...sx
171
- };
172
- const clickHandler = React.useCallback(event => {
173
- if (disabled) return;
174
- if (!event.defaultPrevented) onAction(event);
175
- }, [onAction, disabled]);
176
- return /*#__PURE__*/React.createElement(Box, _extends({
177
- as: "li",
178
- sx: styles,
179
- "data-component": "ActionList.Item",
180
- onClick: clickHandler,
181
- ref: forwardedRef
182
- }, props), /*#__PURE__*/React.createElement(ItemContext.Provider, {
183
- value: {
184
- registerSlot,
185
- deregisterSlot
186
- }
187
- }, /*#__PURE__*/React.createElement(Selection, {
188
- selected: selected,
189
- disabled: disabled
190
- }), slots.LeadingVisual, /*#__PURE__*/React.createElement(Box, {
191
- "data-component": "ActionList.Item--Main",
192
- sx: {
193
- display: 'flex',
194
- flexDirection: 'column',
195
- flexGrow: 1,
196
- minWidth: 0
197
- }
198
- }, /*#__PURE__*/React.createElement(Box, {
199
- sx: {
200
- display: 'flex'
201
- }
202
- }, /*#__PURE__*/React.createElement(Box, {
203
- sx: {
204
- display: 'flex',
205
- flexGrow: 1,
206
- alignItems: 'baseline',
207
- minWidth: 0
208
- }
209
- }, /*#__PURE__*/React.createElement("span", null, props.children), slots.InlineDescription), slots.TrailingVisual), slots.BlockDescription)));
210
- });
211
- Item.displayName = 'ActionList.Item';
@@ -1,18 +0,0 @@
1
- /**
2
- *
3
- * showItemDividers
4
- * deepmerge sx
5
- * change as= ul | div based on context of menu or not?
6
- * should selectionVariant be single by default or nothing. ask for explicit choice?
7
- */
8
- import React from 'react';
9
- import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
10
- import { SxProp } from '../sx';
11
- export declare type ListProps = {
12
- variant?: 'inset' | 'full';
13
- selectionVariant?: 'single' | 'multiple';
14
- } & SxProp;
15
- declare type ContextProps = Pick<ListProps, 'selectionVariant' | 'variant'>;
16
- export declare const ListContext: React.Context<ContextProps>;
17
- export declare const List: PolymorphicForwardRefComponent<"ul", ListProps>;
18
- export {};
@@ -1,42 +0,0 @@
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
- *
5
- * showItemDividers
6
- * deepmerge sx
7
- * change as= ul | div based on context of menu or not?
8
- * should selectionVariant be single by default or nothing. ask for explicit choice?
9
- */
10
- import React from 'react';
11
- import Box from '../Box';
12
- import { get } from '../constants';
13
- export const ListContext = /*#__PURE__*/React.createContext({});
14
- export const List = /*#__PURE__*/React.forwardRef(({
15
- variant = 'inset',
16
- selectionVariant = 'single',
17
- sx = {},
18
- ...props
19
- }, forwardedRef) => {
20
- const styles = {
21
- margin: 0,
22
- fontSize: get('fontSizes.1'),
23
- lineHeight: '20px',
24
- // TODO: check if we replace this already
25
- paddingInlineStart: 0,
26
- // reset ul styles
27
- paddingY: variant === 'inset' ? get('space.2') : 0,
28
- ...sx
29
- };
30
- return /*#__PURE__*/React.createElement(Box, _extends({
31
- as: "ul",
32
- sx: styles
33
- }, props, {
34
- ref: forwardedRef
35
- }), /*#__PURE__*/React.createElement(ListContext.Provider, {
36
- value: {
37
- variant,
38
- selectionVariant
39
- }
40
- }, props.children));
41
- });
42
- List.displayName = 'ActionList';
@@ -1,5 +0,0 @@
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 {};
@@ -1,50 +0,0 @@
1
- import React from 'react';
2
- import { CheckIcon } from '@primer/octicons-react';
3
- import { useTheme } from '../ThemeProvider';
4
- import { ListContext } from './List';
5
- import { LeadingVisualContainer } from './Visuals';
6
- export const Selection = ({
7
- selected,
8
- disabled
9
- }) => {
10
- const {
11
- selectionVariant
12
- } = React.useContext(ListContext);
13
- const {
14
- theme
15
- } = useTheme();
16
- if (typeof selected === 'undefined') return null;
17
-
18
- if (selectionVariant === 'single') {
19
- return /*#__PURE__*/React.createElement(LeadingVisualContainer, null, selected && /*#__PURE__*/React.createElement(CheckIcon, {
20
- fill: theme === null || theme === void 0 ? void 0 : theme.colors.text.primary
21
- }));
22
- }
23
-
24
- if (selectionVariant === 'multiple') {
25
- /**
26
- * readOnly is required because we are doing a one-way bind to `checked`
27
- * aria-readonly="false" tells screen that they can still interact with the checkbox
28
- * TODO: not sure if disabled & aria-label be here or should we apply it on the instance as props
29
- * TODO: aria-label should come from the text part of the slot
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
-
49
- return null;
50
- };
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { SxProp } from '../sx';
3
- import { ItemProps } from './Item';
4
- declare type VisualProps = Pick<ItemProps, 'variant' | 'disabled' | 'sx'> & {
5
- children: React.ReactNode;
6
- };
7
- export declare const LeadingVisualContainer: React.FC<SxProp>;
8
- export declare type LeadingVisualProps = VisualProps;
9
- export declare const LeadingVisual: React.FC<VisualProps>;
10
- export declare type TrailingVisualProps = VisualProps;
11
- export declare const TrailingVisual: React.FC<VisualProps>;
12
- export {};
@@ -1,76 +0,0 @@
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 { ItemContext, getVariantStyles } from './Item';
7
- export const LeadingVisualContainer = ({
8
- sx = {},
9
- ...props
10
- }) => {
11
- return /*#__PURE__*/React.createElement(Box, _extends({
12
- as: "span",
13
- sx: {
14
- height: '20px',
15
- // match height of text row
16
- minWidth: get('space.3'),
17
- maxWidth: '20px',
18
- // square (same as height)
19
- display: 'flex',
20
- justifyContent: 'center',
21
- alignItems: 'center',
22
- flexShrink: 0,
23
- marginRight: 2,
24
- ...sx
25
- }
26
- }, props));
27
- };
28
- LeadingVisualContainer.displayName = "LeadingVisualContainer";
29
- export const LeadingVisual = ({
30
- variant,
31
- disabled,
32
- sx = {},
33
- ...props
34
- }) => {
35
- const {
36
- registerSlot,
37
- deregisterSlot
38
- } = React.useContext(ItemContext);
39
- React.useLayoutEffect(() => {
40
- registerSlot('LeadingVisual', /*#__PURE__*/React.createElement(LeadingVisualContainer, _extends({
41
- sx: {
42
- color: getVariantStyles(variant, disabled).iconColor,
43
- svg: {
44
- fontSize: 0
45
- },
46
- ...sx
47
- }
48
- }, props), props.children));
49
- return () => deregisterSlot('LeadingVisual');
50
- }, [variant, disabled, props.children]);
51
- return null;
52
- };
53
- export const TrailingVisual = ({
54
- variant,
55
- disabled,
56
- ...props
57
- }) => {
58
- const {
59
- registerSlot,
60
- deregisterSlot
61
- } = React.useContext(ItemContext);
62
- React.useLayoutEffect(() => {
63
- registerSlot('TrailingVisual', /*#__PURE__*/React.createElement(Box, _extends({
64
- as: "span",
65
- sx: {
66
- height: '20px',
67
- // match height of text row
68
- flexShrink: 0,
69
- color: getVariantStyles(variant, disabled).annotationColor,
70
- marginLeft: 2
71
- }
72
- }, props), props.children));
73
- return () => deregisterSlot('TrailingVisual');
74
- }, [variant, disabled, props.children]);
75
- return null;
76
- };
@@ -1,30 +0,0 @@
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
- };
@@ -1,30 +0,0 @@
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
- };
@@ -1,26 +0,0 @@
1
- /// <reference types="react" />
2
- import { Group } from './Group';
3
- import { Divider } from './Divider';
4
- export type { ListProps as ActionListProps } from './List';
5
- export type { GroupProps } from './Group';
6
- export type { ItemProps } from './Item';
7
- export type { DescriptionProps } from './Description';
8
- export type { LeadingVisualProps, TrailingVisualProps } from './Visuals';
9
- /**
10
- * Collection of list-related components.
11
- */
12
- export declare const ActionList: import("@radix-ui/react-polymorphic").ForwardRefComponent<"ul", import("./List").ListProps> & {
13
- /** Collects related `Items` in an `ActionList`. */
14
- Group: typeof Group;
15
- /** An actionable or selectable `Item` with an optional icon and description. */
16
- Item: import("@radix-ui/react-polymorphic").ForwardRefComponent<"li", import("./Item").ItemProps>;
17
- /** Visually separates `Item`s or `Group`s in an `ActionList`. */
18
- Divider: typeof Divider;
19
- Description: import("react").FC<import("./Description").DescriptionProps>;
20
- LeadingVisual: import("react").FC<Pick<import("./Item").ItemProps, "sx" | "disabled" | "variant"> & {
21
- children: import("react").ReactNode;
22
- }>;
23
- TrailingVisual: import("react").FC<Pick<import("./Item").ItemProps, "sx" | "disabled" | "variant"> & {
24
- children: import("react").ReactNode;
25
- }>;
26
- };
@@ -1,23 +0,0 @@
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
- });