Skip to content

Commit

Permalink
feat: create dropdown-item plugin component (#21)
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 2e8adc3 commit 2ab85c5
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,30 @@ export default withShurikenUI({
border: 'muted-200', // you can use arbitrary value like '[#fff]'
borderDark: 'muted-600',
},
dropdownItem: {
itemRounded: 'md',
textPosition: 'left',
textSize: 'sm',
duration: '300',
notActive: {
text: 'muted-500',
},
default: {
bg: 'muted-100',
bgDark: 'muted-700',
text: 'primary-500',
},
contrast: {
bg: 'muted-100',
bgDark: 'muted-900',
text: 'primary-500',
},
rounded: {
default: 'md',
smooth: 'lg',
curved: 'xl',
},
},
focus: {
offset: '2',
width: '1',
Expand Down
84 changes: 84 additions & 0 deletions src/plugins/components/dropdown-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../options'

const defaultDropdownItemConfig = {
itemRounded: 'md',
textPosition: 'left',
textSize: 'sm',
duration: '300',
notActive: {
text: 'muted-500',
},
default: {
bg: 'muted-100',
bgDark: 'muted-700',
text: 'primary-500',
},
contrast: {
bg: 'muted-100',
bgDark: 'muted-900',
text: 'primary-500',
},
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.dropdownItem'
) satisfies typeof defaultDropdownItemConfig

addComponents({
[`.${prefix}-dropdown-item`]: {
[`@apply flex w-full items-center justify-start gap-2 rounded-${config.itemRounded} px-3 py-2 text-${config.textPosition} text-${config.textSize} cursor-pointer transition-colors duration-${config.duration}`]:
{},

[`.${prefix}-item-content`]: {
[`@apply grow`]: {},
},
[`&:not(.${prefix}-active)`]: {
[`@apply text-${config.notActive.text}`]: {},
},
[`&.${prefix}-item-default`]: {
[`&.${prefix}-active, &:hover`]: {
[`@apply bg-${config.default.bg} dark:bg-${config.default.bgDark} text-${config.default.text}`]:
{},
},
},
[`&.${prefix}-item-contrast`]: {
[`&.${prefix}-active, &:hover`]: {
[`@apply bg-${config.contrast.bg} dark:bg-${config.contrast.bgDark} text-${config.contrast.text}`]:
{},
},
},
[`&.${prefix}-item-rounded`]: {
[`@apply rounded-${config.rounded.default}`]: {},
},
[`&.${prefix}-item-smooth`]: {
[`@apply rounded-${config.rounded.smooth}`]: {},
},
[`&.${prefix}-item-curved`]: {
[`@apply rounded-${config.rounded.curved}`]: {},
},
},
})
}
},
function () {
return {
theme: {
shurikenUi: {
dropdownItem: defaultDropdownItemConfig,
},
},
}
}
)
2 changes: 2 additions & 0 deletions src/plugins/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import buttonClose from './button-close'
import buttonIcon from './button-icon'
import buttonGroup from './button-group'
import dropdown from './dropdown'
import dropdownItem from './dropdown-item'
import dropdownDivider from './dropdown-divider'
import inputFile from './input-file'
import focus from './focus'
Expand Down Expand Up @@ -51,6 +52,7 @@ const components = [
buttonIcon,
buttonGroup,
dropdown,
dropdownItem,
dropdownDivider,
inputFile,
focus,
Expand Down

0 comments on commit 2ab85c5

Please sign in to comment.