@cypress-design/react-accordion 0.1.0 → 0.1.2
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/Accordion.rootstory.tsx +3 -1
- package/Accordion.stories.mdx +33 -8
- package/Accordion.tsx +15 -3
- package/AccordionReact.cy.tsx +42 -0
- package/CHANGELOG.md +12 -0
- package/dist/constants.d.ts +1 -1
- package/dist/index.es.mjs +8 -7
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +8 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/react/Accordion.d.ts +7 -0
- package/dist/react/Accordion.d.ts.map +1 -1
- package/package.json +1 -1
package/Accordion.rootstory.tsx
CHANGED
|
@@ -8,6 +8,7 @@ export default (options: AccordionStoryOptions = {}) => {
|
|
|
8
8
|
title = 'Accordion Title',
|
|
9
9
|
description = 'Vestibulum id ligula porta felis euismod semper. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla.',
|
|
10
10
|
icon = IconActionQuestionMarkCircle,
|
|
11
|
+
iconEl,
|
|
11
12
|
separator = true,
|
|
12
13
|
open = false,
|
|
13
14
|
fullWidthContent = false,
|
|
@@ -19,7 +20,8 @@ export default (options: AccordionStoryOptions = {}) => {
|
|
|
19
20
|
<Accordion
|
|
20
21
|
title={title}
|
|
21
22
|
description={description}
|
|
22
|
-
icon={icon}
|
|
23
|
+
icon={iconEl ? null : icon}
|
|
24
|
+
iconEl={iconEl}
|
|
23
25
|
separator={separator}
|
|
24
26
|
open={open}
|
|
25
27
|
fullWidthContent={fullWidthContent}
|
package/Accordion.stories.mdx
CHANGED
|
@@ -6,6 +6,7 @@ import AccordionStory from './Accordion.rootstory'
|
|
|
6
6
|
import { FIGMA_URL } from '../constants'
|
|
7
7
|
|
|
8
8
|
import { Accordion } from './Accordion'
|
|
9
|
+
import { IconActionQuestionMarkCircle } from '@cypress-design/react-icon'
|
|
9
10
|
|
|
10
11
|
<h1>Accordion<span className="text-lg font-normal"> - v{version}</span></h1>
|
|
11
12
|
|
|
@@ -29,10 +30,10 @@ import Accordion from '@cypress-design/react-accordion'
|
|
|
29
30
|
</Canvas>
|
|
30
31
|
|
|
31
32
|
```tsx
|
|
32
|
-
<Accordion
|
|
33
|
+
<Accordion
|
|
33
34
|
icon={IconActionQuestionMarkCircle}
|
|
34
|
-
title="Accordion Title"
|
|
35
|
-
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
35
|
+
title="Accordion Title"
|
|
36
|
+
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
36
37
|
separator
|
|
37
38
|
>
|
|
38
39
|
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis nemo minus, sapiente magni ...
|
|
@@ -65,8 +66,8 @@ import Accordion from '@cypress-design/react-accordion'
|
|
|
65
66
|
```tsx
|
|
66
67
|
<Accordion
|
|
67
68
|
icon={IconActionQuestionMarkCircle}
|
|
68
|
-
title="Accordion Title"
|
|
69
|
-
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
69
|
+
title="Accordion Title"
|
|
70
|
+
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
70
71
|
>
|
|
71
72
|
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis nemo minus, sapiente magni ...
|
|
72
73
|
</Accordion>
|
|
@@ -99,10 +100,34 @@ import Accordion from '@cypress-design/react-accordion'
|
|
|
99
100
|
</Canvas>
|
|
100
101
|
|
|
101
102
|
```tsx
|
|
102
|
-
<Accordion
|
|
103
|
+
<Accordion
|
|
103
104
|
icon={IconActionQuestionMarkCircle}
|
|
104
|
-
title="Accordion Title"
|
|
105
|
-
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
105
|
+
title="Accordion Title"
|
|
106
|
+
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
107
|
+
separator
|
|
108
|
+
open
|
|
109
|
+
>
|
|
110
|
+
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis nemo minus, sapiente magni ...
|
|
111
|
+
</Accordion>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Icon as element
|
|
115
|
+
|
|
116
|
+
If you need classes or props for your icon, you can pass it in as an element with props.
|
|
117
|
+
|
|
118
|
+
<Canvas withSource="none">
|
|
119
|
+
<Story name="Icon as element">
|
|
120
|
+
<AccordionStory iconEl={<IconActionQuestionMarkCircle strokeColor="red-600" fillColor="red-50" />} />
|
|
121
|
+
</Story>
|
|
122
|
+
</Canvas>
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<Accordion
|
|
126
|
+
iconEl={
|
|
127
|
+
<IconActionQuestionMarkCircle strokeColor="red-600" fillColor="red-50" />
|
|
128
|
+
}
|
|
129
|
+
title="Accordion Title"
|
|
130
|
+
description="Vestibulum id ligula porta felis euismod semper. Nulla... "
|
|
106
131
|
separator
|
|
107
132
|
open
|
|
108
133
|
>
|
package/Accordion.tsx
CHANGED
|
@@ -6,7 +6,14 @@ import { DetailsAnimation } from '@cypress-design/details-animation'
|
|
|
6
6
|
import { IconChevronDownSmall } from '@cypress-design/react-icon'
|
|
7
7
|
|
|
8
8
|
export interface AccordionPropsReact extends AccordionProps {
|
|
9
|
+
/**
|
|
10
|
+
* Icon to be displayed on the left of the the heading. Overridden by the iconEl prop, if both are provided.
|
|
11
|
+
*/
|
|
9
12
|
icon?: React.FC<React.SVGProps<SVGSVGElement>>
|
|
13
|
+
/**
|
|
14
|
+
* Element to be displayed on the left of the the heading. Overrides the icon prop, if both are provided.
|
|
15
|
+
*/
|
|
16
|
+
iconEl?: React.ReactNode
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
export const Accordion: React.FC<
|
|
@@ -15,6 +22,7 @@ export const Accordion: React.FC<
|
|
|
15
22
|
title,
|
|
16
23
|
description,
|
|
17
24
|
icon: Icon,
|
|
25
|
+
iconEl,
|
|
18
26
|
separator = false,
|
|
19
27
|
children,
|
|
20
28
|
headingClassName,
|
|
@@ -34,13 +42,17 @@ export const Accordion: React.FC<
|
|
|
34
42
|
<details {...rest} className={clsx(rest.className)} ref={details}>
|
|
35
43
|
<summary
|
|
36
44
|
className={clsx(
|
|
37
|
-
'flex items-center',
|
|
38
45
|
CssClasses.summary,
|
|
39
46
|
headingClassName ?? CssClasses.summaryColor
|
|
40
47
|
)}
|
|
41
48
|
>
|
|
42
|
-
{
|
|
43
|
-
|
|
49
|
+
{Boolean(iconEl) && <span className={CssClasses.icon}>{iconEl}</span>}
|
|
50
|
+
|
|
51
|
+
{Icon && !iconEl && <Icon className={CssClasses.icon} />}
|
|
52
|
+
|
|
53
|
+
{(Icon || iconEl) && separator && (
|
|
54
|
+
<hr className={CssClasses.separator} />
|
|
55
|
+
)}
|
|
44
56
|
<div className="flex-grow pr-16px">
|
|
45
57
|
<div
|
|
46
58
|
className={clsx(
|
package/AccordionReact.cy.tsx
CHANGED
|
@@ -4,10 +4,52 @@ import * as React from 'react'
|
|
|
4
4
|
import { mount } from 'cypress/react'
|
|
5
5
|
import AccordionStory from './Accordion.rootstory'
|
|
6
6
|
import assertions from '../assertions'
|
|
7
|
+
import Accordion from './Accordion'
|
|
8
|
+
import { IconActionQuestionMarkCircle } from '@cypress-design/react-icon'
|
|
7
9
|
|
|
8
10
|
describe('Accordion', () => {
|
|
9
11
|
function mountStory(options: Parameters<typeof AccordionStory>[0] = {}) {
|
|
10
12
|
mount(<AccordionStory {...options} />)
|
|
11
13
|
}
|
|
14
|
+
|
|
12
15
|
assertions(mountStory)
|
|
16
|
+
|
|
17
|
+
it('can be passed an icon as a prop', () => {
|
|
18
|
+
mount(
|
|
19
|
+
<Accordion title="hi" icon={IconActionQuestionMarkCircle}></Accordion>
|
|
20
|
+
).get('summary svg')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('can be passed an icon as an element', () => {
|
|
24
|
+
mount(
|
|
25
|
+
<Accordion
|
|
26
|
+
title="hi"
|
|
27
|
+
iconEl={
|
|
28
|
+
<IconActionQuestionMarkCircle
|
|
29
|
+
data-cy="icon-element"
|
|
30
|
+
strokeColor="red-600"
|
|
31
|
+
fillColor="red-50"
|
|
32
|
+
/>
|
|
33
|
+
}
|
|
34
|
+
></Accordion>
|
|
35
|
+
).get('[data-cy=icon-element]')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('when passed both icon and iconEl, iconEl overrides icon', () => {
|
|
39
|
+
mount(
|
|
40
|
+
<Accordion
|
|
41
|
+
title="hi"
|
|
42
|
+
icon={IconActionQuestionMarkCircle}
|
|
43
|
+
iconEl={
|
|
44
|
+
<IconActionQuestionMarkCircle
|
|
45
|
+
data-cy="icon-element"
|
|
46
|
+
strokeColor="red-600"
|
|
47
|
+
fillColor="red-50"
|
|
48
|
+
/>
|
|
49
|
+
}
|
|
50
|
+
></Accordion>
|
|
51
|
+
).get('[data-cy=icon-element]')
|
|
52
|
+
|
|
53
|
+
cy.get('summary').find('svg').should('have.length', 2)
|
|
54
|
+
})
|
|
13
55
|
})
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @cypress-design/react-accordion
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`68718d5`](https://github.com/cypress-io/cypress-design/commit/68718d5b75ac8affec83d3af3c849c8288282aa3) Thanks [@elevatebart](https://github.com/elevatebart)! - add flex-nowrap to accomodate safari 14 (on percy)
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#133](https://github.com/cypress-io/cypress-design/pull/133) [`73250a9`](https://github.com/cypress-io/cypress-design/commit/73250a9d65a890e4be74009978214f49c64e9fce) Thanks [@elevatebart](https://github.com/elevatebart)! - remove duplicate classes on the summary
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/constants.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const CssClasses: {
|
|
|
15
15
|
export interface AccordionProps {
|
|
16
16
|
/**
|
|
17
17
|
* Main indigo title.
|
|
18
|
-
* > [NOTE]
|
|
18
|
+
* > [NOTE] Its color and font can be customized using `titleClassName`.
|
|
19
19
|
*/
|
|
20
20
|
title: string;
|
|
21
21
|
/**
|
package/dist/index.es.mjs
CHANGED
|
@@ -44,7 +44,7 @@ function __rest$1(s, e) {
|
|
|
44
44
|
|
|
45
45
|
var CssClasses = {
|
|
46
46
|
details: '',
|
|
47
|
-
summary: 'details-none min-h-65px py-12px card open:rounded-b-none px-24px flex items-center',
|
|
47
|
+
summary: 'details-none min-h-65px py-12px card open:rounded-b-none px-24px flex flex-row flex-nowrap items-center',
|
|
48
48
|
summaryColor: 'bg-white',
|
|
49
49
|
summaryTitle: 'text-18px leading-28px font-medium',
|
|
50
50
|
summaryTitleColor: 'text-indigo-500',
|
|
@@ -104,7 +104,7 @@ var compileReactIconProperties = function (_a) {
|
|
|
104
104
|
}
|
|
105
105
|
return newAttributes;
|
|
106
106
|
}, {});
|
|
107
|
-
var componentProps = __assign({ width: size, height: size, fill: 'none', dangerouslySetInnerHTML: {
|
|
107
|
+
var componentProps = __assign({ width: size, height: size, viewBox: "0 0 " + size + " " + size, fill: 'none', dangerouslySetInnerHTML: {
|
|
108
108
|
__html: body
|
|
109
109
|
} }, filteredAttributes);
|
|
110
110
|
if (attributes.className) {
|
|
@@ -131,7 +131,7 @@ var IconChevronDownSmall = function (props) {
|
|
|
131
131
|
/* <windicss-keep class=""> */
|
|
132
132
|
|
|
133
133
|
var Accordion = function (_a) {
|
|
134
|
-
var title = _a.title, description = _a.description, Icon = _a.icon, _b = _a.separator, separator = _b === void 0 ? false : _b, children = _a.children, headingClassName = _a.headingClassName, titleClassName = _a.titleClassName, descriptionClassName = _a.descriptionClassName, fullWidthContent = _a.fullWidthContent, rest = __rest$1(_a, ["title", "description", "icon", "separator", "children", "headingClassName", "titleClassName", "descriptionClassName", "fullWidthContent"]);
|
|
134
|
+
var title = _a.title, description = _a.description, Icon = _a.icon, iconEl = _a.iconEl, _b = _a.separator, separator = _b === void 0 ? false : _b, children = _a.children, headingClassName = _a.headingClassName, titleClassName = _a.titleClassName, descriptionClassName = _a.descriptionClassName, fullWidthContent = _a.fullWidthContent, rest = __rest$1(_a, ["title", "description", "icon", "iconEl", "separator", "children", "headingClassName", "titleClassName", "descriptionClassName", "fullWidthContent"]);
|
|
135
135
|
var details = React.useRef(null);
|
|
136
136
|
var content = React.useRef(null);
|
|
137
137
|
React.useEffect(function () {
|
|
@@ -140,9 +140,10 @@ var Accordion = function (_a) {
|
|
|
140
140
|
}
|
|
141
141
|
}, []);
|
|
142
142
|
return (React.createElement("details", __assign$1({}, rest, { className: clsx(rest.className), ref: details }),
|
|
143
|
-
React.createElement("summary", { className: clsx(
|
|
144
|
-
|
|
145
|
-
Icon &&
|
|
143
|
+
React.createElement("summary", { className: clsx(CssClasses.summary, headingClassName !== null && headingClassName !== void 0 ? headingClassName : CssClasses.summaryColor) },
|
|
144
|
+
Boolean(iconEl) && React.createElement("span", { className: CssClasses.icon }, iconEl),
|
|
145
|
+
Icon && !iconEl && React.createElement(Icon, { className: CssClasses.icon }),
|
|
146
|
+
(Icon || iconEl) && separator && (React.createElement("hr", { className: CssClasses.separator })),
|
|
146
147
|
React.createElement("div", { className: "flex-grow pr-16px" },
|
|
147
148
|
React.createElement("div", { className: clsx(titleClassName !== null && titleClassName !== void 0 ? titleClassName : CssClasses.summaryTitleColor, CssClasses.summaryTitle) }, title),
|
|
148
149
|
description && (React.createElement("div", { className: clsx(CssClasses.summaryDescription, descriptionClassName !== null && descriptionClassName !== void 0 ? descriptionClassName : CssClasses.summaryDescriptionColor) }, description))),
|
|
@@ -152,5 +153,5 @@ var Accordion = function (_a) {
|
|
|
152
153
|
|
|
153
154
|
export { Accordion as default };
|
|
154
155
|
|
|
155
|
-
/* <windicss-keep class="flex
|
|
156
|
+
/* <windicss-keep class="flex-grow pr-16px open:icon-dark-gray-500 details-none min-h-65px py-12px card open:rounded-b-none px-24px flex flex-row flex-nowrap items-center bg-white text-18px leading-28px font-medium text-indigo-500 text-14px leading-20px font-normal text-gray-700 mr-24px flex-shrink-0 w-1px h-40px bg-gray-100 mr-16px transition transform rotate-0 open:rotate-180 border border-gray-100 rounded-b-md border-t-0 py-16px"> */
|
|
156
157
|
//# sourceMappingURL=index.es.mjs.map
|