-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create dropdown-item plugin component (#21)
Co-authored-by: Sacha Stafyniak <sacha@digisquad.io>
- Loading branch information
1 parent
2e8adc3
commit 2ab85c5
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters