@sproutsocial/seeds-react-accordion 0.4.32 → 0.4.46
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/dist/accordion.css +159 -0
- package/dist/esm/index.js +236 -78
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +235 -79
- package/dist/index.js.map +1 -1
- package/package.json +21 -10
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -4
- package/.turbo/turbo-build.log +0 -21
- package/CHANGELOG.md +0 -527
- package/jest.config.js +0 -9
- package/src/Accordion.stories.tsx +0 -844
- package/src/Accordion.tsx +0 -83
- package/src/AccordionContent.tsx +0 -23
- package/src/AccordionItem.tsx +0 -11
- package/src/AccordionTrigger.tsx +0 -161
- package/src/AccordionTypes.ts +0 -80
- package/src/__tests__/accordion.test.tsx +0 -536
- package/src/index.ts +0 -7
- package/src/styled.d.ts +0 -7
- package/src/styles.ts +0 -164
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -12
package/src/Accordion.tsx
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React, { createContext, type ReactElement } from "react";
|
|
2
|
-
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
3
|
-
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
4
|
-
import { type TypeAccordionProps } from "./AccordionTypes";
|
|
5
|
-
|
|
6
|
-
export const AccordionContext = createContext<{
|
|
7
|
-
triggerIcon: ReactElement | null;
|
|
8
|
-
triggerPosition: string;
|
|
9
|
-
styled: boolean;
|
|
10
|
-
}>({
|
|
11
|
-
triggerIcon: null,
|
|
12
|
-
triggerPosition: "",
|
|
13
|
-
styled: false,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const Accordion = ({
|
|
17
|
-
children,
|
|
18
|
-
collapsible,
|
|
19
|
-
defaultValue = ["item-0"],
|
|
20
|
-
triggerPosition = "right",
|
|
21
|
-
triggerIcon = <Icon className="triggerIcon" name="chevron-down-outline" />,
|
|
22
|
-
type = "multiple",
|
|
23
|
-
styled = true,
|
|
24
|
-
value,
|
|
25
|
-
onValueChange,
|
|
26
|
-
}: TypeAccordionProps) => {
|
|
27
|
-
const contextValue = {
|
|
28
|
-
triggerIcon: React.isValidElement(triggerIcon) ? triggerIcon : null,
|
|
29
|
-
triggerPosition,
|
|
30
|
-
styled,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (type === "single") {
|
|
34
|
-
// Determine if controlled or uncontrolled
|
|
35
|
-
const isControlled = value !== undefined;
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<RadixAccordion.Root
|
|
39
|
-
type="single"
|
|
40
|
-
value={
|
|
41
|
-
isControlled ? (Array.isArray(value) ? value[0] : value) : undefined
|
|
42
|
-
}
|
|
43
|
-
defaultValue={
|
|
44
|
-
!isControlled && defaultValue
|
|
45
|
-
? Array.isArray(defaultValue)
|
|
46
|
-
? defaultValue[0]
|
|
47
|
-
: defaultValue
|
|
48
|
-
: undefined
|
|
49
|
-
}
|
|
50
|
-
onValueChange={onValueChange as ((value: string) => void) | undefined}
|
|
51
|
-
collapsible={collapsible}
|
|
52
|
-
>
|
|
53
|
-
<AccordionContext.Provider value={contextValue}>
|
|
54
|
-
{children}
|
|
55
|
-
</AccordionContext.Provider>
|
|
56
|
-
</RadixAccordion.Root>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Multiple mode
|
|
61
|
-
const isControlled = value !== undefined;
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<RadixAccordion.Root
|
|
65
|
-
type="multiple"
|
|
66
|
-
value={
|
|
67
|
-
isControlled ? (Array.isArray(value) ? value : [value]) : undefined
|
|
68
|
-
}
|
|
69
|
-
defaultValue={
|
|
70
|
-
!isControlled && defaultValue
|
|
71
|
-
? Array.isArray(defaultValue)
|
|
72
|
-
? defaultValue
|
|
73
|
-
: [defaultValue]
|
|
74
|
-
: undefined
|
|
75
|
-
}
|
|
76
|
-
onValueChange={onValueChange as ((value: string[]) => void) | undefined}
|
|
77
|
-
>
|
|
78
|
-
<AccordionContext.Provider value={contextValue}>
|
|
79
|
-
{children}
|
|
80
|
-
</AccordionContext.Provider>
|
|
81
|
-
</RadixAccordion.Root>
|
|
82
|
-
);
|
|
83
|
-
};
|
package/src/AccordionContent.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { StyledRadixAccordionContent, ContentContainer } from "./styles";
|
|
2
|
-
import { type TypeAccordionSystemProps } from "./AccordionTypes";
|
|
3
|
-
import { AccordionContext } from "./Accordion";
|
|
4
|
-
import { useContext } from "react";
|
|
5
|
-
|
|
6
|
-
interface TypeAccordionContentProps extends TypeAccordionSystemProps {
|
|
7
|
-
children?: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const AccordionContent = ({
|
|
11
|
-
children,
|
|
12
|
-
...rest
|
|
13
|
-
}: TypeAccordionContentProps) => {
|
|
14
|
-
const { styled } = useContext(AccordionContext);
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<StyledRadixAccordionContent data-styled={styled}>
|
|
18
|
-
<ContentContainer data-styled={styled} {...rest}>
|
|
19
|
-
{children}
|
|
20
|
-
</ContentContainer>
|
|
21
|
-
</StyledRadixAccordionContent>
|
|
22
|
-
);
|
|
23
|
-
};
|
package/src/AccordionItem.tsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
2
|
-
import { type TypeAccordionItemProps } from "./AccordionTypes";
|
|
3
|
-
import { StyledAccordionItem } from "./styles";
|
|
4
|
-
|
|
5
|
-
export const AccordionItem = ({ children, value }: TypeAccordionItemProps) => {
|
|
6
|
-
return (
|
|
7
|
-
<StyledAccordionItem className="accordion-item" value={value}>
|
|
8
|
-
{children}
|
|
9
|
-
</StyledAccordionItem>
|
|
10
|
-
);
|
|
11
|
-
};
|
package/src/AccordionTrigger.tsx
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { TriggerContainer } from "./styles";
|
|
2
|
-
import { type TypeAccordionTriggerProps } from "./AccordionTypes";
|
|
3
|
-
import { Box } from "@sproutsocial/seeds-react-box";
|
|
4
|
-
import { Button } from "@sproutsocial/seeds-react-button";
|
|
5
|
-
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
6
|
-
import {
|
|
7
|
-
ActionMenu,
|
|
8
|
-
MenuContent,
|
|
9
|
-
MenuItem,
|
|
10
|
-
MenuGroup,
|
|
11
|
-
MenuToggleButton,
|
|
12
|
-
} from "@sproutsocial/seeds-react-menu";
|
|
13
|
-
import React, { useContext } from "react";
|
|
14
|
-
import { AccordionContext } from "./Accordion";
|
|
15
|
-
import { CollapsibleContentHeader } from "@sproutsocial/seeds-react-content-header";
|
|
16
|
-
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
17
|
-
|
|
18
|
-
const MAX_RELATED_ACTIONS = 2;
|
|
19
|
-
|
|
20
|
-
// Wrapper to adapt RadixAccordion.Trigger to the ContentHeader trigger interface
|
|
21
|
-
const AccordionTriggerWrapper = ({
|
|
22
|
-
children,
|
|
23
|
-
}: {
|
|
24
|
-
children: React.ReactElement;
|
|
25
|
-
}) => <RadixAccordion.Trigger asChild>{children}</RadixAccordion.Trigger>;
|
|
26
|
-
|
|
27
|
-
export const AccordionTrigger = ({
|
|
28
|
-
children,
|
|
29
|
-
leftSlot,
|
|
30
|
-
relatedActions,
|
|
31
|
-
overflowMenu,
|
|
32
|
-
rightSlot,
|
|
33
|
-
title,
|
|
34
|
-
headingLevel = "h4",
|
|
35
|
-
...rest
|
|
36
|
-
}: TypeAccordionTriggerProps) => {
|
|
37
|
-
const { triggerIcon, triggerPosition, styled } = useContext(AccordionContext);
|
|
38
|
-
|
|
39
|
-
// Validate and limit related actions
|
|
40
|
-
const validatedActions = relatedActions?.slice(0, MAX_RELATED_ACTIONS);
|
|
41
|
-
|
|
42
|
-
// Extract system props to distribute to appropriate container
|
|
43
|
-
const {
|
|
44
|
-
color,
|
|
45
|
-
padding,
|
|
46
|
-
paddingBottom,
|
|
47
|
-
paddingTop,
|
|
48
|
-
paddingX,
|
|
49
|
-
paddingY,
|
|
50
|
-
paddingLeft,
|
|
51
|
-
paddingRight,
|
|
52
|
-
p,
|
|
53
|
-
pb,
|
|
54
|
-
pt,
|
|
55
|
-
pr,
|
|
56
|
-
pl,
|
|
57
|
-
px,
|
|
58
|
-
py,
|
|
59
|
-
fontFamily,
|
|
60
|
-
fontSize,
|
|
61
|
-
fontStyle,
|
|
62
|
-
fontWeight,
|
|
63
|
-
lineHeight,
|
|
64
|
-
textAlign,
|
|
65
|
-
...triggerProps
|
|
66
|
-
} = rest;
|
|
67
|
-
|
|
68
|
-
const shouldRenderActionsBlock = Boolean(overflowMenu || validatedActions);
|
|
69
|
-
|
|
70
|
-
// Render overflow menu from config
|
|
71
|
-
const renderedOverflowMenu = overflowMenu && (
|
|
72
|
-
<ActionMenu
|
|
73
|
-
menuToggleElement={
|
|
74
|
-
<MenuToggleButton
|
|
75
|
-
aria-label={overflowMenu["aria-label"]}
|
|
76
|
-
appearance="unstyled"
|
|
77
|
-
color={color}
|
|
78
|
-
>
|
|
79
|
-
<Icon name="ellipsis-horizontal-outline" aria-hidden="true" />
|
|
80
|
-
</MenuToggleButton>
|
|
81
|
-
}
|
|
82
|
-
>
|
|
83
|
-
<MenuContent>
|
|
84
|
-
<MenuGroup id="overflow-actions">
|
|
85
|
-
{overflowMenu.items.map((item, index) => {
|
|
86
|
-
const { iconName, id, onClick, children, ...menuItemProps } = item;
|
|
87
|
-
return (
|
|
88
|
-
<MenuItem
|
|
89
|
-
key={id || `overflow-item-${index}`}
|
|
90
|
-
id={id || `overflow-item-${index}`}
|
|
91
|
-
onClick={onClick}
|
|
92
|
-
{...menuItemProps}
|
|
93
|
-
>
|
|
94
|
-
{iconName ? (
|
|
95
|
-
<Box
|
|
96
|
-
display="flex"
|
|
97
|
-
alignItems="center"
|
|
98
|
-
gap="300"
|
|
99
|
-
color={color}
|
|
100
|
-
>
|
|
101
|
-
<Icon name={iconName} />
|
|
102
|
-
{children}
|
|
103
|
-
</Box>
|
|
104
|
-
) : (
|
|
105
|
-
children
|
|
106
|
-
)}
|
|
107
|
-
</MenuItem>
|
|
108
|
-
);
|
|
109
|
-
})}
|
|
110
|
-
</MenuGroup>
|
|
111
|
-
</MenuContent>
|
|
112
|
-
</ActionMenu>
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// Render related actions from config
|
|
116
|
-
const renderedRelatedActions = validatedActions &&
|
|
117
|
-
validatedActions.length > 0 && (
|
|
118
|
-
<Box display="flex">
|
|
119
|
-
{validatedActions.map((action, index) => (
|
|
120
|
-
<Button
|
|
121
|
-
key={`${action.iconName}-${index}`}
|
|
122
|
-
onClick={action.onClick}
|
|
123
|
-
aria-label={action["aria-label"]}
|
|
124
|
-
color={color}
|
|
125
|
-
>
|
|
126
|
-
<Icon name={action.iconName} aria-hidden="true" />
|
|
127
|
-
</Button>
|
|
128
|
-
))}
|
|
129
|
-
</Box>
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
// Compose actions into a single ReactNode for ContentHeader
|
|
133
|
-
const renderedActions = shouldRenderActionsBlock ? (
|
|
134
|
-
<Box mr={300} display="flex">
|
|
135
|
-
{renderedOverflowMenu}
|
|
136
|
-
{renderedRelatedActions}
|
|
137
|
-
</Box>
|
|
138
|
-
) : undefined;
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<TriggerContainer
|
|
142
|
-
data-styled={styled}
|
|
143
|
-
$styled={styled}
|
|
144
|
-
data-qa-trigger="HERE"
|
|
145
|
-
color={color}
|
|
146
|
-
{...triggerProps}
|
|
147
|
-
>
|
|
148
|
-
<CollapsibleContentHeader
|
|
149
|
-
title={title}
|
|
150
|
-
headingLevel={headingLevel}
|
|
151
|
-
leftSlot={leftSlot}
|
|
152
|
-
rightSlot={rightSlot}
|
|
153
|
-
headerActions={renderedActions}
|
|
154
|
-
trigger={AccordionTriggerWrapper}
|
|
155
|
-
triggerPosition={triggerPosition as "left" | "right"}
|
|
156
|
-
triggerIcon={triggerIcon}
|
|
157
|
-
bordered={false}
|
|
158
|
-
/>
|
|
159
|
-
</TriggerContainer>
|
|
160
|
-
);
|
|
161
|
-
};
|
package/src/AccordionTypes.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
type TypeSystemCommonProps,
|
|
4
|
-
type TypeBorderSystemProps,
|
|
5
|
-
type TypeFlexboxSystemProps,
|
|
6
|
-
type TypeLayoutSystemProps,
|
|
7
|
-
type TypeStyledComponentsCommonProps,
|
|
8
|
-
type TypeSystemTypographyProps,
|
|
9
|
-
} from "@sproutsocial/seeds-react-system-props";
|
|
10
|
-
import { type TypeIconName } from "@sproutsocial/seeds-react-icon";
|
|
11
|
-
import { type TypeMenuItemProps } from "@sproutsocial/seeds-react-menu";
|
|
12
|
-
import { type TypeHeadingLevel } from "@sproutsocial/seeds-react-content-header";
|
|
13
|
-
|
|
14
|
-
export interface TypeAccordionSystemProps
|
|
15
|
-
extends Omit<React.ComponentPropsWithoutRef<"div">, "color">,
|
|
16
|
-
TypeStyledComponentsCommonProps,
|
|
17
|
-
TypeSystemCommonProps,
|
|
18
|
-
TypeBorderSystemProps,
|
|
19
|
-
TypeFlexboxSystemProps,
|
|
20
|
-
TypeLayoutSystemProps,
|
|
21
|
-
TypeSystemTypographyProps {}
|
|
22
|
-
|
|
23
|
-
export interface TypeAccordionProps {
|
|
24
|
-
children?: React.ReactNode;
|
|
25
|
-
collapsible?: boolean;
|
|
26
|
-
defaultValue?: string | string[];
|
|
27
|
-
triggerIcon?: React.ReactNode;
|
|
28
|
-
triggerPosition?: "left" | "right";
|
|
29
|
-
type?: "single" | "multiple";
|
|
30
|
-
styled?: boolean;
|
|
31
|
-
/** Controlled value for open accordion items (single mode: string, multiple mode: string[]) */
|
|
32
|
-
value?: string | string[];
|
|
33
|
-
/** Callback fired when accordion items change (single mode: string, multiple mode: string[]) */
|
|
34
|
-
onValueChange?: (value: string | string[]) => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface TypeRelatedAction {
|
|
38
|
-
iconName: TypeIconName;
|
|
39
|
-
onClick: () => void;
|
|
40
|
-
"aria-label": string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface TypeOverflowMenuItem extends TypeMenuItemProps {
|
|
44
|
-
iconName?: TypeIconName;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface TypeOverflowMenuConfig {
|
|
48
|
-
/** Menu items to be rendered in the overflow menu */
|
|
49
|
-
items: TypeOverflowMenuItem[];
|
|
50
|
-
/** Aria label for the overflow menu trigger button. Defaults to "More actions" */
|
|
51
|
-
"aria-label"?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface TypeAccordionItemProps {
|
|
55
|
-
children: React.ReactNode;
|
|
56
|
-
relatedActions?: TypeRelatedAction[];
|
|
57
|
-
overflowMenu?: TypeOverflowMenuConfig;
|
|
58
|
-
value: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Props for AccordionTrigger component
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```tsx
|
|
66
|
-
* <AccordionTrigger
|
|
67
|
-
* title="My Accordion Title"
|
|
68
|
-
* headingLevel="h2"
|
|
69
|
-
* />
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export interface TypeAccordionTriggerProps extends TypeAccordionSystemProps {
|
|
73
|
-
title: string;
|
|
74
|
-
leftSlot?: React.ReactNode;
|
|
75
|
-
relatedActions?: TypeRelatedAction[];
|
|
76
|
-
overflowMenu?: TypeOverflowMenuConfig;
|
|
77
|
-
rightSlot?: React.ReactNode;
|
|
78
|
-
/** The semantic heading level for the accordion title. Defaults to "h4" */
|
|
79
|
-
headingLevel?: TypeHeadingLevel;
|
|
80
|
-
}
|