@sproutsocial/seeds-react-accordion 0.4.2 → 0.4.7
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/.turbo/turbo-build.log +11 -11
- package/CHANGELOG.md +48 -0
- package/dist/esm/index.js +79 -205
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +83 -209
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/AccordionTrigger.tsx +31 -82
- package/src/AccordionTypes.ts +1 -5
- package/src/styles.ts +26 -72
package/src/AccordionTrigger.tsx
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
type TypeAccordionTriggerProps,
|
|
4
|
-
type TypeRelatedAction,
|
|
5
|
-
type TypeOverflowMenuConfig,
|
|
6
|
-
} from "./AccordionTypes";
|
|
7
|
-
import { FlexCenter, StyledAccordionArea, TriggerContainer } from "./styles";
|
|
1
|
+
import { TriggerContainer } from "./styles";
|
|
2
|
+
import { type TypeAccordionTriggerProps } from "./AccordionTypes";
|
|
8
3
|
import { Box } from "@sproutsocial/seeds-react-box";
|
|
9
4
|
import { Button } from "@sproutsocial/seeds-react-button";
|
|
10
5
|
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
@@ -15,11 +10,20 @@ import {
|
|
|
15
10
|
MenuGroup,
|
|
16
11
|
MenuToggleButton,
|
|
17
12
|
} from "@sproutsocial/seeds-react-menu";
|
|
18
|
-
import { useContext } from "react";
|
|
13
|
+
import React, { useContext } from "react";
|
|
19
14
|
import { AccordionContext } from "./Accordion";
|
|
15
|
+
import { CollapsibleContentHeader } from "@sproutsocial/seeds-react-content-header";
|
|
16
|
+
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
20
17
|
|
|
21
18
|
const MAX_RELATED_ACTIONS = 2;
|
|
22
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
|
+
|
|
23
27
|
export const AccordionTrigger = ({
|
|
24
28
|
children,
|
|
25
29
|
leftSlot,
|
|
@@ -61,37 +65,6 @@ export const AccordionTrigger = ({
|
|
|
61
65
|
...triggerProps
|
|
62
66
|
} = rest;
|
|
63
67
|
|
|
64
|
-
const spacingProps = {
|
|
65
|
-
padding,
|
|
66
|
-
paddingBottom,
|
|
67
|
-
paddingTop,
|
|
68
|
-
paddingX,
|
|
69
|
-
paddingY,
|
|
70
|
-
paddingLeft,
|
|
71
|
-
paddingRight,
|
|
72
|
-
p,
|
|
73
|
-
pb,
|
|
74
|
-
pt,
|
|
75
|
-
pr,
|
|
76
|
-
pl,
|
|
77
|
-
px,
|
|
78
|
-
py,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// When you destructure color from rest, it might be null, which is incompatible with what the styled component expects. We need to filter out null or undefined values from typographyProps before spreading them.
|
|
82
|
-
|
|
83
|
-
const typographyProps = Object.fromEntries(
|
|
84
|
-
Object.entries({
|
|
85
|
-
color,
|
|
86
|
-
fontFamily,
|
|
87
|
-
fontSize,
|
|
88
|
-
fontStyle,
|
|
89
|
-
fontWeight,
|
|
90
|
-
lineHeight,
|
|
91
|
-
textAlign,
|
|
92
|
-
}).filter(([_, value]) => value != null)
|
|
93
|
-
);
|
|
94
|
-
|
|
95
68
|
const shouldRenderActionsBlock = Boolean(overflowMenu || validatedActions);
|
|
96
69
|
|
|
97
70
|
// Render overflow menu from config
|
|
@@ -156,6 +129,14 @@ export const AccordionTrigger = ({
|
|
|
156
129
|
</Box>
|
|
157
130
|
);
|
|
158
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
|
+
|
|
159
140
|
return (
|
|
160
141
|
<TriggerContainer
|
|
161
142
|
data-styled={styled}
|
|
@@ -164,49 +145,17 @@ export const AccordionTrigger = ({
|
|
|
164
145
|
color={color}
|
|
165
146
|
{...triggerProps}
|
|
166
147
|
>
|
|
167
|
-
<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data-styled={styled}
|
|
179
|
-
{...typographyProps}
|
|
180
|
-
>
|
|
181
|
-
{title}
|
|
182
|
-
</TitleStyles>
|
|
183
|
-
{rightSlot}
|
|
184
|
-
</FlexCenter>
|
|
185
|
-
{triggerIcon}
|
|
186
|
-
</StyledAccordionArea>
|
|
187
|
-
) : (
|
|
188
|
-
<StyledAccordionArea>
|
|
189
|
-
<FlexCenter>
|
|
190
|
-
<Box mr={300}>{triggerIcon}</Box>
|
|
191
|
-
{leftSlot}
|
|
192
|
-
<TitleStyles
|
|
193
|
-
as={headingLevel}
|
|
194
|
-
data-styled={styled}
|
|
195
|
-
{...typographyProps}
|
|
196
|
-
>
|
|
197
|
-
{title}
|
|
198
|
-
</TitleStyles>
|
|
199
|
-
</FlexCenter>
|
|
200
|
-
{rightSlot}
|
|
201
|
-
</StyledAccordionArea>
|
|
202
|
-
)}
|
|
203
|
-
</StyledRadixAccordionTrigger>
|
|
204
|
-
{shouldRenderActionsBlock && (
|
|
205
|
-
<Box mr={300} display="flex">
|
|
206
|
-
{renderedOverflowMenu}
|
|
207
|
-
{renderedRelatedActions}
|
|
208
|
-
</Box>
|
|
209
|
-
)}
|
|
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
|
+
/>
|
|
210
159
|
</TriggerContainer>
|
|
211
160
|
);
|
|
212
161
|
};
|
package/src/AccordionTypes.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@sproutsocial/seeds-react-system-props";
|
|
10
10
|
import { type TypeIconName } from "@sproutsocial/seeds-react-icon";
|
|
11
11
|
import { type TypeMenuItemProps } from "@sproutsocial/seeds-react-menu";
|
|
12
|
+
import { type TypeHeadingLevel } from "@sproutsocial/seeds-react-content-header";
|
|
12
13
|
|
|
13
14
|
export interface TypeAccordionSystemProps
|
|
14
15
|
extends Omit<React.ComponentPropsWithoutRef<"div">, "color">,
|
|
@@ -57,11 +58,6 @@ export interface TypeAccordionItemProps {
|
|
|
57
58
|
value: string;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
/**
|
|
61
|
-
* Type for valid heading levels
|
|
62
|
-
*/
|
|
63
|
-
export type TypeHeadingLevel = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
64
|
-
|
|
65
61
|
/**
|
|
66
62
|
* Props for AccordionTrigger component
|
|
67
63
|
*
|
package/src/styles.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
import styled, { css } from "styled-components";
|
|
3
2
|
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
4
|
-
import { fontSize } from "styled-system";
|
|
5
3
|
import {
|
|
6
4
|
BORDER,
|
|
7
5
|
COMMON,
|
|
@@ -9,7 +7,6 @@ import {
|
|
|
9
7
|
LAYOUT,
|
|
10
8
|
TYPOGRAPHY,
|
|
11
9
|
} from "@sproutsocial/seeds-react-system-props";
|
|
12
|
-
import { focusRing } from "@sproutsocial/seeds-react-mixins";
|
|
13
10
|
import { type TypeAccordionSystemProps } from "./AccordionTypes";
|
|
14
11
|
|
|
15
12
|
interface StyledAccordionProps extends TypeAccordionSystemProps {
|
|
@@ -38,45 +35,6 @@ const animations = css`
|
|
|
38
35
|
}
|
|
39
36
|
`;
|
|
40
37
|
|
|
41
|
-
export const StyledRadixAccordionTrigger = styled(
|
|
42
|
-
RadixAccordion.Trigger as React.ComponentType<
|
|
43
|
-
Omit<React.ComponentPropsWithoutRef<typeof RadixAccordion.Trigger>, "color">
|
|
44
|
-
>
|
|
45
|
-
)<StyledAccordionProps>`
|
|
46
|
-
padding: 0;
|
|
47
|
-
width: 100%;
|
|
48
|
-
display: flex;
|
|
49
|
-
align-items: center;
|
|
50
|
-
justify-content: space-between;
|
|
51
|
-
cursor: pointer;
|
|
52
|
-
outline: none;
|
|
53
|
-
border: none;
|
|
54
|
-
background: transparent;
|
|
55
|
-
color: ${({ theme }) => theme.colors.text.body};
|
|
56
|
-
${({ theme }) => theme.typography[200]};
|
|
57
|
-
|
|
58
|
-
.triggerIcon {
|
|
59
|
-
transition: transform 300ms ease-in-out;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
&[data-state="open"] {
|
|
63
|
-
.triggerIcon {
|
|
64
|
-
transform: rotate(-180deg);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
&[data-styled] {
|
|
69
|
-
padding: ${({ theme }) => theme.space[400]};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
&:focus {
|
|
73
|
-
${focusRing}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
${COMMON}
|
|
77
|
-
${TYPOGRAPHY}
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
38
|
export const StyledRadixAccordionContent = styled(
|
|
81
39
|
RadixAccordion.Content
|
|
82
40
|
)<StyledAccordionProps>`
|
|
@@ -109,17 +67,6 @@ export const StyledRadixAccordionContent = styled(
|
|
|
109
67
|
}
|
|
110
68
|
`;
|
|
111
69
|
|
|
112
|
-
export const StyledAccordionArea = styled.div`
|
|
113
|
-
display: flex;
|
|
114
|
-
align-items: center;
|
|
115
|
-
justify-content: space-between;
|
|
116
|
-
width: 100%;
|
|
117
|
-
`;
|
|
118
|
-
export const FlexCenter = styled.div`
|
|
119
|
-
display: flex;
|
|
120
|
-
align-items: center;
|
|
121
|
-
`;
|
|
122
|
-
|
|
123
70
|
export const ContentContainer = styled.div<StyledAccordionProps>`
|
|
124
71
|
color: ${({ theme }) => theme.colors.text.body};
|
|
125
72
|
background: transparent;
|
|
@@ -147,6 +94,32 @@ export const TriggerContainer = styled.div<StyledAccordionProps>`
|
|
|
147
94
|
display: flex;
|
|
148
95
|
align-items: center;
|
|
149
96
|
color: ${({ theme }) => theme.colors.text.body};
|
|
97
|
+
${({ theme }) => theme.typography[200]};
|
|
98
|
+
|
|
99
|
+
/* Override Text.Headline styles to match original accordion trigger typography */
|
|
100
|
+
h1,
|
|
101
|
+
h2,
|
|
102
|
+
h3,
|
|
103
|
+
h4,
|
|
104
|
+
h5,
|
|
105
|
+
h6 {
|
|
106
|
+
font-size: inherit;
|
|
107
|
+
font-weight: normal;
|
|
108
|
+
line-height: inherit;
|
|
109
|
+
color: inherit;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&[data-styled="true"] {
|
|
113
|
+
h1,
|
|
114
|
+
h2,
|
|
115
|
+
h3,
|
|
116
|
+
h4,
|
|
117
|
+
h5,
|
|
118
|
+
h6 {
|
|
119
|
+
font-weight: ${({ theme }) => theme.fontWeights.semibold};
|
|
120
|
+
color: ${({ theme }) => theme.colors.text.headline};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
150
123
|
|
|
151
124
|
${({ $styled, theme }) =>
|
|
152
125
|
$styled &&
|
|
@@ -189,22 +162,3 @@ export const TriggerContainer = styled.div<StyledAccordionProps>`
|
|
|
189
162
|
${LAYOUT}
|
|
190
163
|
${FLEXBOX}
|
|
191
164
|
`;
|
|
192
|
-
|
|
193
|
-
export const TitleStyles = styled.h4.attrs<
|
|
194
|
-
StyledAccordionProps & { as?: string }
|
|
195
|
-
>((props) => ({
|
|
196
|
-
as: props.as || "h4",
|
|
197
|
-
}))<StyledAccordionProps>`
|
|
198
|
-
margin: 0;
|
|
199
|
-
font-weight: normal;
|
|
200
|
-
|
|
201
|
-
&[data-styled="true"] {
|
|
202
|
-
font-size: ${({ theme }) => theme.fontSizes[200]};
|
|
203
|
-
font-weight: ${({ theme }) => theme.fontWeights.semibold};
|
|
204
|
-
color: ${({ theme }) => theme.colors.text.headline};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
${COMMON}
|
|
208
|
-
${TYPOGRAPHY}
|
|
209
|
-
${fontSize}
|
|
210
|
-
`;
|