@cypress-design/vue-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.
@@ -0,0 +1,35 @@
1
+ import { IconActionQuestionMarkCircle } from '@cypress-design/vue-icon'
2
+ import type { AccordionStoryOptions } from '../assertions'
3
+ import Accordion from './Accordion.vue'
4
+
5
+ export default (options: AccordionStoryOptions = {}) => {
6
+ const {
7
+ title = 'Accordion Title',
8
+ description = 'Vestibulum id ligula porta felis euismod semper. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla.',
9
+ icon = IconActionQuestionMarkCircle,
10
+ separator = true,
11
+ open = false,
12
+ fullWidthContent = false,
13
+ headingClassName,
14
+ } = options
15
+
16
+ return (
17
+ <div className="m-16px">
18
+ <Accordion
19
+ title={title}
20
+ separator={separator}
21
+ description={description}
22
+ icon={icon}
23
+ open={open}
24
+ fullWidthContent={fullWidthContent}
25
+ headingClassName={headingClassName}
26
+ >
27
+ <p data-cy="content">
28
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore
29
+ omnis nemo minus, sapiente magni laudantium eligendi modi deserunt ea
30
+ non iure consequatur sed id quidem! Ad.
31
+ </p>
32
+ </Accordion>
33
+ </div>
34
+ )
35
+ }
@@ -0,0 +1,109 @@
1
+ import { ArgsTable, Canvas, Meta, Story, Description } from '@storybook/addon-docs'
2
+ import { version } from "./package.json"
3
+ import changelog from "./CHANGELOG.md?raw"
4
+ import { FIGMA_URL } from '../constants'
5
+
6
+ import Accordion from './Accordion.vue'
7
+
8
+ import AccordionStory from './Accordion.rootstory'
9
+
10
+ <h1>Accordion<span className="text-lg font-normal"> - v{version}</span></h1>
11
+
12
+ <Meta title="Accordion" component={Accordion} parameters={{
13
+ design: {
14
+ type: "figma",
15
+ url: FIGMA_URL,
16
+ }
17
+ }} />
18
+
19
+
20
+ ### Usage
21
+
22
+ ```tsx
23
+ import Accordion from '@cypress-design/vue-accordion'
24
+ ```
25
+
26
+ <Canvas withSource="none">
27
+ <Story name="Accordion">
28
+ {AccordionStory()}
29
+ </Story>
30
+ </Canvas>
31
+
32
+ ```html
33
+ <Accordion
34
+ :icon="IconActionQuestionMarkCircle"
35
+ title="Accordion Title"
36
+ description="Vestibulum id ligula porta felis euismod semper. Nulla... "
37
+ separator
38
+ >
39
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis
40
+ nemo minus, sapiente magni ...
41
+ </Accordion>
42
+ ```
43
+
44
+ ### Without separator
45
+
46
+ <Canvas withSource="none">
47
+ <Story name="No Separator">
48
+ {AccordionStory({separator:false})}
49
+ </Story>
50
+ </Canvas>
51
+
52
+ ```html
53
+ <Accordion
54
+ :icon="IconActionQuestionMarkCircle"
55
+ title="Accordion Title"
56
+ description="Vestibulum id ligula porta felis euismod semper. Nulla... "
57
+ >
58
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis
59
+ nemo minus, sapiente magni ...
60
+ </Accordion>
61
+ ```
62
+
63
+ ### Without description
64
+
65
+ <Canvas withSource="none">
66
+ <Story name="No Description">
67
+ {AccordionStory({description:null})}
68
+ </Story>
69
+ </Canvas>
70
+
71
+ ```html
72
+ <Accordion
73
+ :icon="IconActionQuestionMarkCircle"
74
+ title="Accordion Title"
75
+ separator
76
+ open
77
+ >
78
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis
79
+ nemo minus, sapiente magni ...
80
+ </Accordion>
81
+ ```
82
+
83
+ ### Open by default
84
+
85
+ <Canvas withSource="none">
86
+ <Story name="Open">
87
+ {AccordionStory({open:true})}
88
+ </Story>
89
+ </Canvas>
90
+
91
+ ```html
92
+ <Accordion
93
+ :icon="IconActionQuestionMarkCircle"
94
+ title="Accordion Title"
95
+ description="Vestibulum id ligula porta felis euismod semper. Nulla... "
96
+ separator
97
+ open
98
+ >
99
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis
100
+ nemo minus, sapiente magni ...
101
+ </Accordion>
102
+ ```
103
+
104
+ <ArgsTable />
105
+
106
+ <Description>
107
+ {changelog.replace(/^# .+/, '## Changelog')}
108
+ </Description>
109
+
package/Accordion.vue ADDED
@@ -0,0 +1,98 @@
1
+ <template>
2
+ <details ref="details">
3
+ <summary
4
+ class="flex items-center"
5
+ :class="[CssClasses.summary, headingClassName ?? CssClasses.summaryColor]"
6
+ >
7
+ <Icon v-if="props.icon" :class="CssClasses.icon" />
8
+ <hr v-if="props.icon && separator" :class="CssClasses.separator" />
9
+ <div class="flex-grow pr-16px">
10
+ <div
11
+ :class="[
12
+ titleClassName ? titleClassName : CssClasses.summaryTitleColor,
13
+ CssClasses.summaryTitle,
14
+ ]"
15
+ >
16
+ {{ title }}
17
+ </div>
18
+ <div
19
+ v-if="description"
20
+ :class="[
21
+ CssClasses.summaryDescription,
22
+ descriptionClassName ?? CssClasses.summaryDescriptionColor,
23
+ ]"
24
+ >
25
+ {{ description }}
26
+ </div>
27
+ </div>
28
+ <IconChevronDownSmall
29
+ strokeColor="gray-300"
30
+ class="open:icon-dark-gray-500"
31
+ :class="CssClasses.chevron"
32
+ />
33
+ </summary>
34
+ <div ref="content" :class="CssClasses.contentWrapper">
35
+ <!-- @slot expandable body of the collapsible accordion -->
36
+ <slot v-if="fullWidthContent" />
37
+ <div v-else :class="CssClasses.content">
38
+ <slot />
39
+ </div>
40
+ </div>
41
+ </details>
42
+ </template>
43
+
44
+ <script lang="ts" setup>
45
+ import { CssClasses } from '../constants'
46
+ import { DetailsAnimation } from '@cypress-design/details-animation'
47
+ import { IconChevronDownSmall } from '@cypress-design/vue-icon'
48
+ import { FunctionalComponent, onMounted, ref, SVGAttributes } from 'vue'
49
+
50
+ const props = defineProps<{
51
+ /**
52
+ * Main indigo title.
53
+ * [NOTE] It's color and font can be customized using `titleClassName`.
54
+ */
55
+ title: string
56
+ /**
57
+ * Second line in the heading.
58
+ */
59
+ description?: string
60
+ /**
61
+ * Icon to be displayed on the left of the the heading.
62
+ */
63
+ icon?: FunctionalComponent<SVGAttributes>
64
+ /**
65
+ * Should we add a vertical separator between the icon and the text.
66
+ */
67
+ separator?: boolean
68
+ /**
69
+ * Change the font and color of the heading title
70
+ */
71
+ titleClassName?: string
72
+ /**
73
+ * Change the font and color of the heading description
74
+ */
75
+ descriptionClassName?: string
76
+ /**
77
+ * Additional classes to add to the header of the accordion
78
+ * > [NOTE] useful to change the background color of the header
79
+ */
80
+ headingClassName?: string
81
+ /**
82
+ * When using content that needs ti be edge to edge,
83
+ * removes the content wrapper from the content.
84
+ */
85
+ fullWidthContent?: boolean
86
+ }>()
87
+
88
+ const content = ref(null)
89
+ const details = ref(null)
90
+
91
+ onMounted(function () {
92
+ if (details.value && content.value) {
93
+ new DetailsAnimation(details.value, content.value)
94
+ }
95
+ })
96
+
97
+ const Icon = props.icon
98
+ </script>
@@ -0,0 +1,11 @@
1
+ /// <reference types="cypress" />
2
+ import { mount } from 'cypress/vue'
3
+ import assertions from '../assertions'
4
+ import AccordionStory from './Accordion.rootstory'
5
+
6
+ describe('<Accordion/>', () => {
7
+ function mountStory(options: Parameters<typeof AccordionStory>[0] = {}) {
8
+ mount(() => <AccordionStory {...options} />)
9
+ }
10
+ assertions(mountStory)
11
+ })
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @cypress-design/vue-accordion
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#74](https://github.com/cypress-io/cypress-design/pull/74) [`6d8b6fd`](https://github.com/cypress-io/cypress-design/commit/6d8b6fd763b0389d748884c35f4ff6dd73724977) Thanks [@elevatebart](https://github.com/elevatebart)! - create the first version of accordion
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`6d8b6fd`](https://github.com/cypress-io/cypress-design/commit/6d8b6fd763b0389d748884c35f4ff6dd73724977)]:
12
+ - @cypress-design/details-animation@0.0.1
package/ReadMe.md ADDED
@@ -0,0 +1,37 @@
1
+ # Accordion
2
+
3
+ ## Summary
4
+
5
+ Collapsible component with a header and a body.
6
+
7
+ ## install
8
+
9
+ ```bash
10
+ npm install @cypress-design/vue-accordion
11
+ ```
12
+
13
+ or with yarn
14
+
15
+ ```bash
16
+ yarn add @cypress-design/vue-accordion
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import Accordion from '@cypress-design/vue-accordion'
23
+ ```
24
+
25
+ ```vue
26
+ <Accordion
27
+ :icon="IconActionQuestionMarkCircle"
28
+ title="Accordion Title"
29
+ description="Vestibulum id ligula porta felis euismod semper. Nulla... "
30
+ separator
31
+ open
32
+ fullWidthContent
33
+ >
34
+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio dolore omnis
35
+ nemo minus, sapiente magni ...
36
+ </Accordion>
37
+ ```
@@ -0,0 +1,53 @@
1
+ export declare const CssClasses: {
2
+ details: string;
3
+ summary: string;
4
+ summaryColor: string;
5
+ summaryTitle: string;
6
+ summaryTitleColor: string;
7
+ summaryDescription: string;
8
+ summaryDescriptionColor: string;
9
+ icon: string;
10
+ separator: string;
11
+ chevron: string;
12
+ contentWrapper: string;
13
+ content: string;
14
+ };
15
+ export interface AccordionProps {
16
+ /**
17
+ * Main indigo title.
18
+ * > [NOTE] It's color and font can be customized using `titleClassName`.
19
+ */
20
+ title: string;
21
+ /**
22
+ * Second line in the heading.
23
+ */
24
+ description?: string;
25
+ /**
26
+ * Icon to be displayed on the left of the the heading.
27
+ */
28
+ icon?: any;
29
+ /**
30
+ * Should we add a vertical separator between the icon and the text.
31
+ */
32
+ separator?: boolean;
33
+ /**
34
+ * Change the font and color of the heading title
35
+ */
36
+ titleClassName?: string;
37
+ /**
38
+ * Change the font and color of the heading description
39
+ */
40
+ descriptionClassName?: string;
41
+ /**
42
+ * Additional classes to add to the header of the accordion
43
+ * > [NOTE] useful to change the background color of the header
44
+ */
45
+ headingClassName?: string;
46
+ /**
47
+ * When using content that needs ti be edge to edge,
48
+ * removes the content wrapper from the content.
49
+ */
50
+ fullWidthContent?: boolean;
51
+ }
52
+ export declare const FIGMA_URL = "https://www.figma.com/file/1WJ3GVQyMV5e7xVxPg3yID/Design-System?node-id=2232%3A3477";
53
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;CActB,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAA;IACV;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,eAAO,MAAM,SAAS,wFACiE,CAAA"}
@@ -0,0 +1,123 @@
1
+ import { h as g, defineComponent as v, ref as h, onMounted as b, openBlock as m, createElementBlock as d, createElementVNode as u, normalizeClass as s, unref as t, createBlock as N, createCommentVNode as y, toDisplayString as k, createVNode as w, renderSlot as x } from "vue";
2
+ import { DetailsAnimation as D } from "@cypress-design/details-animation";
3
+ import * as z from "@cypress-design/icon-registry";
4
+ import { ICON_COLOR_PROP_NAMES as O } from "@cypress-design/icon-registry";
5
+ const o = {
6
+ details: "",
7
+ summary: "details-none min-h-65px py-12px card open:rounded-b-none px-24px flex items-center",
8
+ summaryColor: "bg-white",
9
+ summaryTitle: "text-18px leading-28px font-medium",
10
+ summaryTitleColor: "text-indigo-500",
11
+ summaryDescription: "text-14px leading-20px font-normal",
12
+ summaryDescriptionColor: "text-gray-700",
13
+ icon: "mr-24px flex-shrink-0",
14
+ separator: "w-1px h-40px bg-gray-100 mr-16px",
15
+ chevron: "flex-shrink-0 transition transform rotate-0 open:rotate-180",
16
+ contentWrapper: "border border-gray-100 rounded-b-md border-t-0",
17
+ content: "px-24px py-16px"
18
+ }, B = ({
19
+ body: e,
20
+ compiledClasses: n,
21
+ size: r,
22
+ class: l,
23
+ interactiveColorsOnGroup: f,
24
+ ...a
25
+ }) => {
26
+ const C = Object.keys(a).reduce((c, p) => (O.includes(p) || (c[p] = a[p]), c), {}), i = {
27
+ width: r,
28
+ height: r,
29
+ fill: "none",
30
+ innerHTML: e,
31
+ ...C
32
+ };
33
+ return n.length && (i.class = n.join(" ")), i;
34
+ }, T = (e) => {
35
+ const { sizeWithDefault: n, compiledClasses: r } = z.getComponentAttributes({ ...e, availableSizes: ["8", "16"] }), l = {
36
+ 8: '<path d="m1 2.5 3 3 3-3" stroke="currentColor" class="icon-dark" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>',
37
+ 16: '<path d="m4 6 4 4 4-4" stroke="currentColor" class="icon-dark" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
38
+ }[n];
39
+ if (!l)
40
+ throw Error(`Icon "chevron-down-small" is not available in size ${n}`);
41
+ return g("svg", B({
42
+ ...e,
43
+ size: n,
44
+ body: l,
45
+ compiledClasses: r
46
+ }));
47
+ }, W = { class: "flex-grow pr-16px" }, S = /* @__PURE__ */ v({
48
+ __name: "Accordion",
49
+ props: {
50
+ title: null,
51
+ description: null,
52
+ icon: null,
53
+ separator: { type: Boolean },
54
+ titleClassName: null,
55
+ descriptionClassName: null,
56
+ headingClassName: null,
57
+ fullWidthContent: { type: Boolean }
58
+ },
59
+ setup(e) {
60
+ const n = e, r = h(null), l = h(null);
61
+ b(function() {
62
+ l.value && r.value && new D(l.value, r.value);
63
+ });
64
+ const f = n.icon;
65
+ return (a, C) => {
66
+ var i, c;
67
+ return m(), d("details", {
68
+ ref_key: "details",
69
+ ref: l
70
+ }, [
71
+ u("summary", {
72
+ class: s(["flex items-center", [t(o).summary, (i = e.headingClassName) != null ? i : t(o).summaryColor]])
73
+ }, [
74
+ n.icon ? (m(), N(t(f), {
75
+ key: 0,
76
+ class: s(t(o).icon)
77
+ }, null, 8, ["class"])) : y("", !0),
78
+ n.icon && e.separator ? (m(), d("hr", {
79
+ key: 1,
80
+ class: s(t(o).separator)
81
+ }, null, 2)) : y("", !0),
82
+ u("div", W, [
83
+ u("div", {
84
+ class: s([
85
+ e.titleClassName ? e.titleClassName : t(o).summaryTitleColor,
86
+ t(o).summaryTitle
87
+ ])
88
+ }, k(e.title), 3),
89
+ e.description ? (m(), d("div", {
90
+ key: 0,
91
+ class: s([
92
+ t(o).summaryDescription,
93
+ (c = e.descriptionClassName) != null ? c : t(o).summaryDescriptionColor
94
+ ])
95
+ }, k(e.description), 3)) : y("", !0)
96
+ ]),
97
+ w(t(T), {
98
+ strokeColor: "gray-300",
99
+ class: s(["open:icon-dark-gray-500", t(o).chevron])
100
+ }, null, 8, ["class"])
101
+ ], 2),
102
+ u("div", {
103
+ ref_key: "content",
104
+ ref: r,
105
+ class: s(t(o).contentWrapper)
106
+ }, [
107
+ e.fullWidthContent ? x(a.$slots, "default", { key: 0 }) : (m(), d("div", {
108
+ key: 1,
109
+ class: s(t(o).content)
110
+ }, [
111
+ x(a.$slots, "default")
112
+ ], 2))
113
+ ], 2)
114
+ ], 512);
115
+ };
116
+ }
117
+ });
118
+ export {
119
+ S as default
120
+ };
121
+
122
+ /* <windicss-keep class="flex items-center flex-grow pr-16px open:icon-dark-gray-500 icon-dark-gray-300 details-none min-h-65px py-12px card open:rounded-b-none px-24px 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"> */
123
+ //# sourceMappingURL=index.es.mjs.map