@sproutsocial/seeds-react-accordion 0.1.0
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/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +7 -0
- package/dist/esm/index.js +267 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +300 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +47 -0
- package/src/Accordion.stories.tsx +563 -0
- package/src/Accordion.tsx +63 -0
- package/src/AccordionContent.tsx +23 -0
- package/src/AccordionItem.tsx +11 -0
- package/src/AccordionTrigger.tsx +188 -0
- package/src/AccordionTypes.ts +54 -0
- package/src/__tests__/accordion.test.tsx +419 -0
- package/src/index.ts +6 -0
- package/src/styled.d.ts +7 -0
- package/src/styles.ts +194 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
package/src/styles.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import * as RadixAccordion from "@radix-ui/react-accordion";
|
|
3
|
+
import {
|
|
4
|
+
BORDER,
|
|
5
|
+
COMMON,
|
|
6
|
+
FLEXBOX,
|
|
7
|
+
LAYOUT,
|
|
8
|
+
TYPOGRAPHY,
|
|
9
|
+
} from "@sproutsocial/seeds-react-system-props";
|
|
10
|
+
import { type TypeAccordionSystemProps } from "./AccordionTypes";
|
|
11
|
+
|
|
12
|
+
interface StyledAccordionProps extends TypeAccordionSystemProps {
|
|
13
|
+
$styled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const StyledAccordionItem = styled(RadixAccordion.Item)``;
|
|
17
|
+
|
|
18
|
+
const animations = css`
|
|
19
|
+
@keyframes slideDown {
|
|
20
|
+
from {
|
|
21
|
+
height: 0;
|
|
22
|
+
}
|
|
23
|
+
to {
|
|
24
|
+
height: var(--radix-accordion-content-height);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@keyframes slideUp {
|
|
29
|
+
from {
|
|
30
|
+
height: var(--radix-accordion-content-height);
|
|
31
|
+
}
|
|
32
|
+
to {
|
|
33
|
+
height: 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export const StyledRadixAccordionTrigger = styled(
|
|
39
|
+
RadixAccordion.Trigger
|
|
40
|
+
)<StyledAccordionProps>`
|
|
41
|
+
padding: 0;
|
|
42
|
+
width: 100%;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: space-between;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
outline: none;
|
|
48
|
+
border: none;
|
|
49
|
+
background: transparent;
|
|
50
|
+
${({ theme }) => theme.typography[200]};
|
|
51
|
+
|
|
52
|
+
.triggerIcon {
|
|
53
|
+
color: ${({ theme }) => theme.colors.icon.base};
|
|
54
|
+
transition: transform 300ms ease-in-out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&[data-state="open"] {
|
|
58
|
+
.triggerIcon {
|
|
59
|
+
transform: rotate(-180deg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&[data-styled] {
|
|
64
|
+
padding: ${({ theme }) => theme.space[400]};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
${COMMON}
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
export const StyledRadixAccordionContent = styled(
|
|
71
|
+
RadixAccordion.Content
|
|
72
|
+
)<StyledAccordionProps>`
|
|
73
|
+
${animations}
|
|
74
|
+
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
|
|
77
|
+
&[data-state="open"] {
|
|
78
|
+
animation: slideDown 300ms ease-in-out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&[data-state="closed"] {
|
|
82
|
+
animation: slideUp 300ms ease-in-out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&[data-styled="true"] {
|
|
86
|
+
border-left: ${({ theme }) =>
|
|
87
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
88
|
+
border-right: ${({ theme }) =>
|
|
89
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
90
|
+
background: ${({ theme }) => theme.colors.container.background.base};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.accordion-item:last-child[data-state="open"] &[data-styled="true"],
|
|
94
|
+
.accordion-item:last-child[data-state="closed"] &[data-styled="true"] {
|
|
95
|
+
border-bottom: ${({ theme }) =>
|
|
96
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
97
|
+
border-bottom-left-radius: ${({ theme }) => theme.radii.outer};
|
|
98
|
+
border-bottom-right-radius: ${({ theme }) => theme.radii.outer};
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
export const StyledAccordionArea = styled.div`
|
|
103
|
+
display: flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
justify-content: space-between;
|
|
106
|
+
width: 100%;
|
|
107
|
+
`;
|
|
108
|
+
export const FlexCenter = styled.div`
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
export const ContentContainer = styled.div<StyledAccordionProps>`
|
|
114
|
+
color: ${({ theme }) => theme.colors.text.body};
|
|
115
|
+
background: transparent;
|
|
116
|
+
font-family: ${({ theme }) => theme.fontFamily};
|
|
117
|
+
${({ theme }) => theme.typography[200]};
|
|
118
|
+
|
|
119
|
+
&[data-styled="true"] {
|
|
120
|
+
padding: ${({ theme }) => theme.space[400]};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.accordion-item:last-child[data-state="open"] &[data-styled="true"],
|
|
124
|
+
.accordion-item:last-child[data-state="closed"] &[data-styled="true"] {
|
|
125
|
+
border-bottom-left-radius: ${({ theme }) => theme.radii.outer};
|
|
126
|
+
border-bottom-right-radius: ${({ theme }) => theme.radii.outer};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
${COMMON}
|
|
130
|
+
${BORDER}
|
|
131
|
+
${LAYOUT}
|
|
132
|
+
${FLEXBOX}
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
export const TriggerContainer = styled.div<StyledAccordionProps>`
|
|
136
|
+
display: flex;
|
|
137
|
+
align-items: center;
|
|
138
|
+
|
|
139
|
+
&[data-styled="true"] {
|
|
140
|
+
border-top: ${({ theme }) =>
|
|
141
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
142
|
+
border-left: ${({ theme }) =>
|
|
143
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
144
|
+
border-right: ${({ theme }) =>
|
|
145
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
146
|
+
background: ${({ theme }) => theme.colors.container.background.base};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.accordion-item[data-state="open"] &[data-styled="true"] {
|
|
150
|
+
border-bottom: ${({ theme }) =>
|
|
151
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.accordion-item[data-state="closed"] &[data-styled="true"] {
|
|
155
|
+
transition: border-bottom-color 0s ease-in-out 0.3s;
|
|
156
|
+
border-bottom: ${({ theme }) =>
|
|
157
|
+
`${theme.borderWidths[500]} solid transparent`};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.accordion-item:first-child &[data-styled="true"] {
|
|
161
|
+
border-top-left-radius: ${({ theme }) => theme.radii.outer};
|
|
162
|
+
border-top-right-radius: ${({ theme }) => theme.radii.outer};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.accordion-item:last-child &[data-styled="true"] {
|
|
166
|
+
border-bottom: ${({ theme }) =>
|
|
167
|
+
`${theme.borderWidths[500]} solid ${theme.colors.container.border.base}`};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.accordion-item:last-child[data-state="closed"] &[data-styled="true"] {
|
|
171
|
+
transition: border-radius 0s linear 0.3s;
|
|
172
|
+
border-bottom-left-radius: ${({ theme }) => theme.radii.outer};
|
|
173
|
+
border-bottom-right-radius: ${({ theme }) => theme.radii.outer};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
${COMMON}
|
|
177
|
+
${BORDER}
|
|
178
|
+
${LAYOUT}
|
|
179
|
+
${FLEXBOX}
|
|
180
|
+
`;
|
|
181
|
+
|
|
182
|
+
export const TitleStyles = styled.h4<StyledAccordionProps>`
|
|
183
|
+
margin: 0;
|
|
184
|
+
font-size: ${({ theme }) => theme.fontSizes[200]};
|
|
185
|
+
font-weight: normal;
|
|
186
|
+
|
|
187
|
+
&[data-styled="true"] {
|
|
188
|
+
font-weight: ${({ theme }) => theme.fontWeights.semibold};
|
|
189
|
+
color: ${({ theme }) => theme.colors.text.headline};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
${COMMON}
|
|
193
|
+
${TYPOGRAPHY}
|
|
194
|
+
`;
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
clean: true,
|
|
7
|
+
legacyOutput: true,
|
|
8
|
+
dts: options.dts,
|
|
9
|
+
external: ["react"],
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
metafile: options.metafile,
|
|
12
|
+
}));
|