Skip to content

Commit

Permalink
feat: add typing for tailwind config
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Nov 16, 2023
1 parent 087eeca commit 20d21fa
Show file tree
Hide file tree
Showing 165 changed files with 4,864 additions and 4,376 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { preset } from './preset'

export default {
content: [],
presets: [preset],
presets: [preset as any],
} satisfies Config
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Config } from 'tailwindcss'
import type { ShurikenUIConfig } from './schema'
import { preset, hasPreset } from './preset'

export * from './preset'

export function withShurikenUI(config: Config) {
export function withShurikenUI(config: ShurikenUIConfig) {
if (hasPreset(config)) {
return config
}
Expand Down
62 changes: 62 additions & 0 deletions src/plugins/components/accordion/accordion.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export const key = 'accordion' as const

export const defaultConfig = {
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',
},
headerInner: {
text: 'muted-800',
textDark: 'white',
},
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 type AccordionConfig = typeof defaultConfig
export interface AccordionPluginConfig {
[key]: AccordionConfig
}
4 changes: 2 additions & 2 deletions src/plugins/components/accordion/accordion.doc.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, Primary, Controls, Story } from '@storybook/blocks'
import * as AccordionStories from './accordion.stories'
import { defaultAccordionConfig } from '.'
import { defaultConfig } from './accordion.config'

<Meta of={AccordionStories} />

Expand Down Expand Up @@ -117,7 +117,7 @@ Accordions can have a plus indicator.

<div class="!mt-4">
<pre >
{JSON.stringify(defaultAccordionConfig, null, 2)}
{JSON.stringify(defaultConfig, null, 2)}
</pre>
</div>

Expand Down
64 changes: 3 additions & 61 deletions src/plugins/components/accordion/index.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,7 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../../options'

export 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',
},
headerInner: {
text: 'muted-800',
textDark: 'white',
},
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',
},
}
import { type AccordionConfig, defaultConfig, key } from './accordion.config'

export default plugin.withOptions(
function (options: PluginOption) {
Expand All @@ -67,10 +12,7 @@ export default plugin.withOptions(
}

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

const config = theme(`shurikenUi.${key}`) satisfies AccordionConfig
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}`]:
Expand Down Expand Up @@ -169,7 +111,7 @@ export default plugin.withOptions(
return {
theme: {
shurikenUi: {
accordion: defaultAccordionConfig,
[key]: defaultConfig,
},
},
}
Expand Down
Loading

0 comments on commit 20d21fa

Please sign in to comment.