Skip to content

Commit 9af8a98

Browse files
feat(#138): accordion (#142)
* chore(#138): accordion template * chore(#138): update accordion and related --------- Co-authored-by: Brian Gilbert <[email protected]>
1 parent 5c0ceae commit 9af8a98

File tree

4 files changed

+144
-9
lines changed

4 files changed

+144
-9
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import CTAccordion from './Accordion.vue'
2+
3+
export default {
4+
title: 'CivicTheme/Molecules/Accordion',
5+
component: CTAccordion,
6+
argTypes: {
7+
theme: {
8+
options: ['dark', 'light'],
9+
control: 'select'
10+
},
11+
},
12+
parameters: {
13+
status: {
14+
type: 'beta',
15+
}
16+
}
17+
}
18+
19+
const Template = (args, { argTypes }) => {
20+
return {
21+
props: Object.keys(argTypes),
22+
template: `<CTAccordion v-bind="$props" v-on="$props">
23+
<template v-if="$props.default">{{ $props.default }}</template>
24+
</CTAccordion>`,
25+
}
26+
}
27+
28+
export const Default = Template.bind({})
29+
Default.storyName = 'Accordion'
30+
Default.args = {
31+
background: false,
32+
expandAll: true,
33+
panels: [
34+
{ title: 'Accordion title 1', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 0 },
35+
{ title: 'Accordion title 2', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 1 },
36+
{ title: 'Accordion title 3', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 2 },
37+
]
38+
}

src/components/Accordion.vue

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<template>
2+
<div
3+
class="ct-accordion"
4+
:class="{
5+
[themeClass]: true,
6+
'ct-accordion--with-background': background
7+
}"
8+
>
9+
<div class="container">
10+
<div class="row">
11+
<div class="col-xxs-12">
12+
<!-- Slot: Content Top -->
13+
<div v-if="$slots['content_top']" class="ct-accordion__content-top">
14+
{{ content_top }}
15+
</div>
16+
17+
<div class="ct-accordion__content">
18+
<ul class="ct-accordion__panels">
19+
<CTCollapsible
20+
v-for="(panel, delta) of panels"
21+
:collapsed="!expandAll && !panel.expanded"
22+
class="ct-accordion__panels__panel"
23+
data-collapsible-duration="250"
24+
data-collapsible-trigger-wide=""
25+
:key="`panel-${delta}`"
26+
panel-class="ct-accordion__panels__panel__content"
27+
tag="li"
28+
>
29+
<template #trigger>
30+
<div class="ct-accordion__panels__panel__header">
31+
<CTButton
32+
class="ct-accordion__panels__panel__header__button"
33+
data-collapsible-trigger=""
34+
:text="panel.title"
35+
/>
36+
</div>
37+
</template>
38+
39+
<CTParagraph class="ct-accordion__panels__panel__content__inner">
40+
<slot name="panel" :panel="{ panel }">
41+
{{ panel.content }}
42+
</slot>
43+
</CTParagraph>
44+
</CTCollapsible>
45+
</ul>
46+
</div>
47+
48+
<!-- Slot: Content Top -->
49+
<div v-if="$slots['content_bottom']" class="ct-accordion__content-bottom">
50+
{{ content_bottom }}
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
</div>
56+
</template>
57+
58+
<script>
59+
import ThemeMixin from '../mixins/theme'
60+
61+
export default {
62+
mixins: [ThemeMixin],
63+
64+
props: {
65+
background: {
66+
type: Boolean,
67+
default: false,
68+
},
69+
expandAll: {
70+
type: Boolean,
71+
default: false,
72+
},
73+
panels: {
74+
type: Array,
75+
default: () => ([])
76+
}
77+
}
78+
}
79+
</script>

src/components/Button.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
<CTIcon
1717
v-if="icon && iconPosition === 'before'"
18-
class="ct-button__icon"
18+
:class="iconClass"
1919
:size="iconSize"
2020
:symbol="icon"
2121
/>
@@ -27,11 +27,10 @@
2727

2828
<CTIcon
2929
v-if="icon && iconPosition === 'after'"
30-
class="ct-button__icon"
30+
:class="iconClass"
3131
:size="iconSize"
3232
:symbol="icon"
3333
/>
34-
3534
</component>
3635
</template>
3736

@@ -50,6 +49,10 @@ export default {
5049
type: String,
5150
default: undefined
5251
},
52+
iconClass: {
53+
type: String,
54+
default: 'ct-button__icon'
55+
},
5356
iconPosition: {
5457
type: String,
5558
default: 'after'

src/components/Collapsible.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<template>
2-
<div
2+
<component :is="tag"
33
data-collapsible="1"
44
v-bind="{
55
'data-collapsible-collapsed': collapsed
66
}"
77
>
8-
<div data-collapsible-trigger="" @click="onClick">
9-
<slot name="trigger">{{ trigger }}</slot>
10-
</div>
11-
<div data-collapsible-panel="">
8+
<slot name="trigger" :trigger="{ onClick, trigger, triggerClass }">
9+
<div :class="triggerClass" data-collapsible-trigger="" @click="onClick">
10+
{{ trigger }}
11+
</div>
12+
</slot>
13+
14+
<div :class="panelClass" data-collapsible-panel="">
1215
<slot />
1316
</div>
14-
</div>
17+
</component>
1518
</template>
1619

1720
<script>
@@ -21,9 +24,21 @@ export default {
2124
type: Boolean,
2225
default: undefined
2326
},
27+
panelClass: {
28+
type: String,
29+
default: undefined
30+
},
31+
tag: {
32+
type: String,
33+
default: 'div'
34+
},
2435
trigger: {
2536
type: String,
2637
default: 'Click me'
38+
},
39+
triggerClass: {
40+
type: String,
41+
default: undefined
2742
}
2843
},
2944

0 commit comments

Comments
 (0)