@primer/components 0.0.0-2021104155230 → 0.0.0-2021104181937
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.
- package/CHANGELOG.md +1 -3
- package/dist/browser.esm.js +474 -473
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +98 -97
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +30 -28
- package/lib/Autocomplete/AutocompleteInput.d.ts +30 -28
- package/lib/Button/Button.d.ts +24 -24
- package/lib/Button/Button.js +1 -1
- package/lib/Button/ButtonClose.d.ts +43 -43
- package/lib/Button/ButtonDanger.d.ts +24 -24
- package/lib/Button/ButtonInvisible.d.ts +24 -24
- package/lib/Button/ButtonOutline.d.ts +24 -24
- package/lib/Button/ButtonPrimary.d.ts +24 -24
- package/lib/CircleOcticon.d.ts +40 -40
- package/lib/DatePicker/DatePicker.d.ts +52 -0
- package/lib/DatePicker/DatePicker.js +109 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +202 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +55 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +363 -0
- package/lib/DatePicker/Day.d.ts +15 -0
- package/lib/DatePicker/Day.js +204 -0
- package/lib/DatePicker/Month.d.ts +8 -0
- package/lib/DatePicker/Month.js +122 -0
- package/lib/DatePicker/dateParser.d.ts +12 -0
- package/lib/DatePicker/dateParser.js +193 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +107 -0
- package/lib/DatePicker/useDatePicker.js +561 -0
- package/lib/Dialog.d.ts +43 -43
- package/lib/Dropdown.d.ts +168 -168
- package/lib/DropdownMenu/DropdownButton.d.ts +44 -44
- package/lib/FilterList.d.ts +40 -40
- package/lib/Position.d.ts +4 -4
- package/lib/SelectMenu/SelectMenu.d.ts +239 -237
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +30 -28
- package/lib/Timeline.d.ts +41 -41
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/sx.d.ts +0 -2
- package/lib/sx.js +0 -8
- package/lib/theme-preval.js +0 -79
- package/lib/utils/testing.d.ts +0 -13
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +30 -28
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +30 -28
- package/lib-esm/Button/Button.d.ts +24 -24
- package/lib-esm/Button/Button.js +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +43 -43
- package/lib-esm/Button/ButtonDanger.d.ts +24 -24
- package/lib-esm/Button/ButtonInvisible.d.ts +24 -24
- package/lib-esm/Button/ButtonOutline.d.ts +24 -24
- package/lib-esm/Button/ButtonPrimary.d.ts +24 -24
- package/lib-esm/CircleOcticon.d.ts +40 -40
- package/lib-esm/DatePicker/DatePicker.d.ts +52 -0
- package/lib-esm/DatePicker/DatePicker.js +92 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +40 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +332 -0
- package/lib-esm/DatePicker/Day.d.ts +15 -0
- package/lib-esm/DatePicker/Day.js +180 -0
- package/lib-esm/DatePicker/Month.d.ts +8 -0
- package/lib-esm/DatePicker/Month.js +98 -0
- package/lib-esm/DatePicker/dateParser.d.ts +12 -0
- package/lib-esm/DatePicker/dateParser.js +179 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
- package/lib-esm/DatePicker/useDatePicker.js +526 -0
- package/lib-esm/Dialog.d.ts +43 -43
- package/lib-esm/Dropdown.d.ts +168 -168
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +44 -44
- package/lib-esm/FilterList.d.ts +40 -40
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/SelectMenu/SelectMenu.d.ts +239 -237
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +30 -28
- package/lib-esm/Timeline.d.ts +41 -41
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/sx.d.ts +0 -2
- package/lib-esm/sx.js +1 -3
- package/lib-esm/theme-preval.js +0 -79
- package/lib-esm/utils/testing.d.ts +0 -13
- package/package.json +9 -10
- package/lib/ActionList2/Description.d.ts +0 -12
- package/lib/ActionList2/Description.js +0 -53
- package/lib/ActionList2/Divider.d.ts +0 -5
- package/lib/ActionList2/Divider.js +0 -35
- package/lib/ActionList2/Group.d.ts +0 -11
- package/lib/ActionList2/Group.js +0 -57
- package/lib/ActionList2/Header.d.ts +0 -26
- package/lib/ActionList2/Header.js +0 -55
- package/lib/ActionList2/Item.d.ts +0 -71
- package/lib/ActionList2/Item.js +0 -223
- package/lib/ActionList2/LinkItem.d.ts +0 -17
- package/lib/ActionList2/LinkItem.js +0 -57
- package/lib/ActionList2/List.d.ts +0 -26
- package/lib/ActionList2/List.js +0 -51
- package/lib/ActionList2/Selection.d.ts +0 -5
- package/lib/ActionList2/Selection.js +0 -70
- package/lib/ActionList2/Visuals.d.ts +0 -11
- package/lib/ActionList2/Visuals.js +0 -90
- package/lib/ActionList2/index.d.ts +0 -40
- package/lib/ActionList2/index.js +0 -47
- package/lib/experiments.d.ts +0 -1
- package/lib/experiments.js +0 -18
- package/lib/utils/create-slots.d.ts +0 -17
- package/lib/utils/create-slots.js +0 -105
- package/lib/utils/use-force-update.d.ts +0 -1
- package/lib/utils/use-force-update.js +0 -19
- package/lib-esm/ActionList2/Description.d.ts +0 -12
- package/lib-esm/ActionList2/Description.js +0 -37
- package/lib-esm/ActionList2/Divider.d.ts +0 -5
- package/lib-esm/ActionList2/Divider.js +0 -23
- package/lib-esm/ActionList2/Group.d.ts +0 -11
- package/lib-esm/ActionList2/Group.js +0 -40
- package/lib-esm/ActionList2/Header.d.ts +0 -26
- package/lib-esm/ActionList2/Header.js +0 -44
- package/lib-esm/ActionList2/Item.d.ts +0 -71
- package/lib-esm/ActionList2/Item.js +0 -197
- package/lib-esm/ActionList2/LinkItem.d.ts +0 -17
- package/lib-esm/ActionList2/LinkItem.js +0 -43
- package/lib-esm/ActionList2/List.d.ts +0 -26
- package/lib-esm/ActionList2/List.js +0 -34
- package/lib-esm/ActionList2/Selection.d.ts +0 -5
- package/lib-esm/ActionList2/Selection.js +0 -52
- package/lib-esm/ActionList2/Visuals.d.ts +0 -11
- package/lib-esm/ActionList2/Visuals.js +0 -68
- package/lib-esm/ActionList2/index.d.ts +0 -40
- package/lib-esm/ActionList2/index.js +0 -33
- package/lib-esm/experiments.d.ts +0 -1
- package/lib-esm/experiments.js +0 -2
- package/lib-esm/utils/create-slots.d.ts +0 -17
- package/lib-esm/utils/create-slots.js +0 -84
- package/lib-esm/utils/use-force-update.d.ts +0 -1
- package/lib-esm/utils/use-force-update.js +0 -6
@@ -1,26 +0,0 @@
|
|
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 {};
|
@@ -1,34 +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 { 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';
|
@@ -1,52 +0,0 @@
|
|
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";
|
@@ -1,11 +0,0 @@
|
|
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 {};
|
@@ -1,68 +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 { 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";
|
@@ -1,40 +0,0 @@
|
|
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
|
-
};
|
@@ -1,33 +0,0 @@
|
|
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
|
-
});
|
package/lib-esm/experiments.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './ActionList2';
|
package/lib-esm/experiments.js
DELETED
@@ -1,17 +0,0 @@
|
|
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> | undefined;
|
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;
|
@@ -1,84 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { useForceUpdate } from './use-force-update';
|
3
|
-
/** createSlots is a factory that can create a
|
4
|
-
* typesafe Slots + Slot pair to use in a component definition
|
5
|
-
* For example: ActionList.Item uses createSlots to get a Slots wrapper
|
6
|
-
* + Slot component that is used by LeadingVisual, Description
|
7
|
-
*/
|
8
|
-
|
9
|
-
const createSlots = slotNames => {
|
10
|
-
const SlotsContext = /*#__PURE__*/React.createContext({
|
11
|
-
registerSlot: () => null,
|
12
|
-
unregisterSlot: () => null,
|
13
|
-
context: {}
|
14
|
-
});
|
15
|
-
/** Slots uses a Double render strategy inspired by [reach-ui/descendants](https://github.com/reach/reach-ui/tree/develop/packages/descendants)
|
16
|
-
* Slot registers themself with the Slots parent.
|
17
|
-
* When all the children have mounted = registered themselves in slot,
|
18
|
-
* we re-render the parent component to render with slots
|
19
|
-
*/
|
20
|
-
|
21
|
-
const Slots = ({
|
22
|
-
context = {},
|
23
|
-
children
|
24
|
-
}) => {
|
25
|
-
// initialise slots
|
26
|
-
const slotsDefinition = {};
|
27
|
-
slotNames.map(name => slotsDefinition[name] = null);
|
28
|
-
const slotsRef = React.useRef(slotsDefinition);
|
29
|
-
const rerenderWithSlots = useForceUpdate();
|
30
|
-
const [isMounted, setIsMounted] = React.useState(false); // fires after all the effects in children
|
31
|
-
|
32
|
-
React.useEffect(() => {
|
33
|
-
rerenderWithSlots();
|
34
|
-
setIsMounted(true);
|
35
|
-
}, [rerenderWithSlots]);
|
36
|
-
const registerSlot = React.useCallback((name, contents) => {
|
37
|
-
slotsRef.current[name] = contents; // don't render until the component mounts = all slots are registered
|
38
|
-
|
39
|
-
if (isMounted) rerenderWithSlots();
|
40
|
-
}, [isMounted, rerenderWithSlots]); // Slot can be removed from the tree as well,
|
41
|
-
// we need to unregister them from the slot
|
42
|
-
|
43
|
-
const unregisterSlot = React.useCallback(name => {
|
44
|
-
slotsRef.current[name] = null;
|
45
|
-
rerenderWithSlots();
|
46
|
-
}, [rerenderWithSlots]);
|
47
|
-
/**
|
48
|
-
* Slots uses a render prop API so abstract the
|
49
|
-
* implementation detail of using a context provider.
|
50
|
-
*/
|
51
|
-
|
52
|
-
const slots = slotsRef.current;
|
53
|
-
return /*#__PURE__*/React.createElement(SlotsContext.Provider, {
|
54
|
-
value: {
|
55
|
-
registerSlot,
|
56
|
-
unregisterSlot,
|
57
|
-
context
|
58
|
-
}
|
59
|
-
}, children(slots));
|
60
|
-
};
|
61
|
-
|
62
|
-
const Slot = ({
|
63
|
-
name,
|
64
|
-
children
|
65
|
-
}) => {
|
66
|
-
const {
|
67
|
-
registerSlot,
|
68
|
-
unregisterSlot,
|
69
|
-
context
|
70
|
-
} = React.useContext(SlotsContext);
|
71
|
-
React.useEffect(() => {
|
72
|
-
registerSlot(name, typeof children === 'function' ? children(context) : children);
|
73
|
-
return () => unregisterSlot(name);
|
74
|
-
}, [name, children, registerSlot, unregisterSlot, context]);
|
75
|
-
return null;
|
76
|
-
};
|
77
|
-
|
78
|
-
return {
|
79
|
-
Slots,
|
80
|
-
Slot
|
81
|
-
};
|
82
|
-
};
|
83
|
-
|
84
|
-
export default createSlots;
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const useForceUpdate: () => () => void;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
// Inspired from reach-ui: https://github.com/reach/reach-ui/blob/develop/packages/utils/src/use-force-update.ts
|
2
|
-
import React from 'react';
|
3
|
-
export const useForceUpdate = () => {
|
4
|
-
const [, rerender] = React.useState({});
|
5
|
-
return React.useCallback(() => rerender({}), []);
|
6
|
-
};
|