Skip to content

Commit

Permalink
feat: create progress-circle plugin component (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpsmartdesign authored Jul 23, 2023
1 parent 038bf40 commit 94b59dd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export default withShurikenUI({
text: 'primary-800',
textDark: 'primary-200',
},
progressCircle: {
circleDuration: '500',
default: {
text: 'muted-200',
textDark: 'muted-700',
stroke: 'current',
},
contrast: {
text: 'muted-200',
textDark: 'muted-900',
stroke: 'current',
}
},
slimscroll: {
width: '[6px]',
bg: 'black/5',
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import label from './label'
import mark from './mark'
import mask from './mask'
import placeload from './placeload'
import progressCircle from './progress-circle'
import slimscroll from './slimscroll'
import tooltip from './tooltip'

Expand All @@ -19,6 +20,7 @@ const components = [
mark,
mask,
placeload,
progressCircle,
slimscroll,
tooltip,
]
Expand Down
58 changes: 58 additions & 0 deletions src/plugins/components/progress-circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../options'

const defaultProgressCircleConfig = {
circleDuration: '500',
default: {
text: 'muted-200',
textDark: 'muted-700',
stroke: 'current',
},
contrast: {
text: 'muted-200',
textDark: 'muted-900',
stroke: 'current',
},
}

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

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

addComponents({
[`.${prefix}-progress-circle`]: {
[`@apply relative inline-flex items-center justify-center`]: {},

[`circle:nth-child(2)`]: {
// Is this a component or a class?
[`@apply stroke-current transition-all duration-${config.circleDuration}`]:
{},
},
[`&.${prefix}-progress-default circle:first-child`]: {
[`@apply text-${config.default.text} dark:text-${config.default.textDark} stroke-${config.default.stroke}`]:
{},
},
[`&.${prefix}-progress-contrast circle:first-child`]: {
[`@apply text-${config.contrast.text} dark:text-${config.contrast.textDark} stroke-${config.contrast.stroke}`]:
{},
},
},
})
}
},
function () {
return {
theme: {
shurikenUi: {
progressCircle: defaultProgressCircleConfig,
},
},
}
}
)

0 comments on commit 94b59dd

Please sign in to comment.