Skip to content

Commit

Permalink
feat: create accordion plugin component (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Sacha Stafyniak <sacha@digisquad.io>
  • Loading branch information
bpsmartdesign and stafyniaksacha authored Jul 23, 2023
1 parent 3d28052 commit 8033b9b
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,56 @@ export default withShurikenUI({
theme: {
extend: {
shurikenUi: {
accordion: {
size: 'full',
border: 'muted-200',
borderDark: 'muted-700',
bg: 'white',
bgDark: 'muted-800',
detail: {
border: 'muted-200',
borderDark: 'muted-700',
},
detailAndDot: {
bg: 'muted-200',
bgDark: 'muted-700',
},
detailOpenAndDot: {
bg: 'primary-500',
},
dot: {
size: '3',
rounded: 'full',
duration: '300',
},
outer: {
border: 'muted-200',
borderDark: 'muted-700',
bg: 'white',
bgDark: 'muted-700/60',
size: '8',
rounded: 'full',
duration: '300',
},
chevronIcon: {
size: '4',
duration: '300',
},
plusIcon: {
size: '4',
duration: '300',
},
content: {
space: '5',
font: 'sans',
text: 'muted-500',
textDark: 'muted-400',
},
rounded: {
default: 'md',
smooth: 'lg',
curved: 'xl',
}
dropdown: {
textPosition: 'start',
contextButton: {
Expand Down
165 changes: 165 additions & 0 deletions src/plugins/components/accordion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../options'

const defaultAccordionConfig = {
size: 'full',
border: 'muted-200',
borderDark: 'muted-700',
bg: 'white',
bgDark: 'muted-800',
detail: {
border: 'muted-200',
borderDark: 'muted-700',
},
detailAndDot: {
bg: 'muted-200',
bgDark: 'muted-700',
},
detailOpenAndDot: {
bg: 'primary-500',
},
dot: {
size: '3',
rounded: 'full',
duration: '300',
},
outer: {
border: 'muted-200',
borderDark: 'muted-700',
bg: 'white',
bgDark: 'muted-700/60',
size: '8',
rounded: 'full',
duration: '300',
},
chevronIcon: {
size: '4',
duration: '300',
},
plusIcon: {
size: '4',
duration: '300',
},
content: {
space: '5',
font: 'sans',
text: 'muted-500',
textDark: 'muted-400',
},
rounded: {
default: 'md',
smooth: 'lg',
curved: 'xl',
},
}

export default plugin.withOptions(
function (options: PluginOption) {
const { prefix } = defu(options, defaultPluginOptions)

return function ({ addComponents, theme }) {
const config = theme(
'shurikenUi.accordion'
) satisfies typeof defaultAccordionConfig

addComponents({
[`.${prefix}-accordion`]: {
[`@apply w-${config.size} border-${config.border} dark:border-${config.borderDark} dark:bg-${config.bgDark} block overflow-hidden border bg-${config.bg}`]:
{},

[`.${prefix}-accordion-detail[open]:not(:first-child)`]: {
[`@apply border-${config.detail.border} dark:border-${config.detail.borderDark} border-t`]:
{},
},
[`.${prefix}-accordion-detail .${prefix}-accordion-dot`]: {
[`@apply bg-${config.detailAndDot.bg} dark:bg-${config.detailAndDot.bgDark}`]:
{},
},
[`.${prefix}-accordion-detail[open] .${prefix}-accordion-dot`]: {
[`@apply bg-${config.detailOpenAndDot.bg}`]: {},
},
[`.${prefix}-accordion-summary`]: {
[`@apply cursor-pointer list-none outline-none`]: {},
},
[`.${prefix}-accordion-header`]: {
[`@apply flex items-center justify-between`]: {},
},
[`.${prefix}-accordion-dot`]: {
[`@apply ms-2 h-${config.dot.size} w-${config.dot.size} rounded-${config.dot.rounded} transition-colors duration-${config.dot.duration}`]:
{},
},
[`.${prefix}-icon-outer`]: {
[`@apply border-${config.outer.border} dark:border-${config.outer.borderDark} dark:bg-${config.outer.bgDark} ms-2 flex h-${config.outer.size} w-${config.outer.size} items-center justify-center rounded-${config.outer.rounded} border bg-${config.outer.bg} transition-all duration-${config.outer.duration}`]:
{},
},
[`.${prefix}-chevron-icon`]: {
[`@apply h-${config.chevronIcon.size} w-${config.chevronIcon.size} transition-transform duration-${config.chevronIcon.duration}`]:
{},
},
[`.${prefix}-plus-icon`]: {
[`@apply h-${config.plusIcon.size} w-${config.plusIcon.size} transition-transform duration-${config.plusIcon.duration}`]:
{},
},
[`.${prefix}-accordion-content`]: {
[`@apply px-${config.content.space} pb-${config.content.space} font-${config.content.font} text-${config.content.text} dark:text-${config.content.textDark}`]:
{},
},
[`&.${prefix}-accordion-dot`]: {
[`.${prefix}-accordion-header`]: {
[`@apply p-5`]: {},
},
},
[`&.${prefix}-accordion-chevron, &.${prefix}-accordion-plus`]: {
[`.${prefix}-accordion-header`]: {
[`@apply px-5 py-3`]: {},
},
},
[`&.${prefix}-accordion-chevron`]: {
[`.${prefix}-accordion-detail[open] .${prefix}-icon-outer`]: {
[`@apply rotate-180`]: {},
},
},
[`&.${prefix}-accordion-plus`]: {
[`.${prefix}-accordion-detail[open] .${prefix}-icon-outer`]: {
[`@apply rotate-45`]: {},
},
},
[`&.${prefix}-accordion-rounded`]: {
[`&.${prefix}-accordion:first-child`]: {
[`@apply rounded-t-${config.rounded.default}`]: {},
},
[`&.${prefix}-accordion:last-child`]: {
[`@apply rounded-b-${config.rounded.default}`]: {},
},
},
[`&.${prefix}-accordion-smooth`]: {
[`&.${prefix}-accordion:first-child`]: {
[`@apply rounded-t-${config.rounded.smooth}`]: {},
},
[`&.${prefix}-accordion:last-child`]: {
[`@apply rounded-b-${config.rounded.smooth}`]: {},
},
},
[`&.${prefix}-accordion-curved`]: {
[`&.${prefix}-accordion:first-child`]: {
[`@apply rounded-t-${config.rounded.curved}`]: {},
},
[`&.${prefix}-accordion:last-child`]: {
[`@apply rounded-b-${config.rounded.curved}`]: {},
},
},
},
})
}
},
function () {
return {
theme: {
shurikenUi: {
accordion: defaultAccordionConfig,
},
},
}
}
)
2 changes: 2 additions & 0 deletions src/plugins/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption } from '../options'
import accordion from './accordion'
import card from './card'
import avatarGroup from './avatar-group'
import autocomplete from './autocomplete'
Expand Down Expand Up @@ -47,6 +48,7 @@ import tag from './tag'
import breadcrumb from './breadcrumb'

const components = [
accordion,
card,
breadcrumb,
avatarGroup,
Expand Down

0 comments on commit 8033b9b

Please sign in to comment.