Skip to content

Commit

Permalink
feat: create switch thin plugin component (#37)
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 df22937 commit cac03fd
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1947,12 +1947,14 @@ export default withShurikenUI({
bgHover: 'black/20',
bgHoverDark: 'white/20',
},
switchThin: {
switchBall: {
handle: {
border: 'muted-300',
borderDark: 'muted-600',
bg: 'white',
bgDark: 'muted-700',
size: '6',
size: '5',
rounded: 'full',
},
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 @@ -26,6 +26,7 @@ import select from './select'
import radio from './radio'
import progressCircle from './progress-circle'
import slimscroll from './slimscroll'
import switchThin from './switch-thin'
import switchBall from './switch-ball'
import textarea from './textarea'
import tooltip from './tooltip'
Expand Down Expand Up @@ -55,6 +56,7 @@ const components = [
radio,
progressCircle,
slimscroll,
switchThin,
switchBall,
snack,
textarea,
Expand Down
135 changes: 135 additions & 0 deletions src/plugins/components/switch-thin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../options'

const defaultSwitchThinConfig = {
handle: {
border: 'muted-300',
borderDark: 'muted-600',
bg: 'white',
bgDark: 'muted-700',
size: '6',
rounded: 'full',
},
track: {
bg: 'muted-300',
bgDark: 'muted-600',
rounded: 'full',
duration: '300',
},
singleLabel: {
text: 'muted-400',
font: 'sans',
textSize: 'sm',
},
dualLabel: {
label: {
font: 'heading',
fontWeight: 'medium',
text: 'muted-800',
textDark: 'white',
textSize: 'sm',
},
sublabel: {
text: 'muted-400',
textSize: 'xs',
font: 'sans',
},
},
input: {
size: 'full',
},
primary: 'primary-400',
info: 'info-400',
success: 'success-400',
warning: 'warning-400',
danger: 'danger-400',
}

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

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

addComponents({
[`.${prefix}-switch-thin`]: {
[`@apply flex cursor-pointer items-center`]: {},

[`.${prefix}-switch-thin-outer`]: {
[`@apply relative block h-4`]: {},
},
[`.${prefix}-switch-thin-handle`]: {
[`@apply border-${config.handle.border} dark:border-${config.handle.borderDark} dark:bg-${config.handle.bgDark} absolute -start-1 top-1/2 flex h-${config.handle.size} w-${config.handle.size} -translate-y-1/2 items-center justify-center rounded-${config.handle.rounded} border bg-${config.handle.bg} shadow transition`]:
{},
},
[`.${prefix}-switch-thin-track`]: {
[`@apply bg-${config.track.bg} dark:bg-${config.track.bgDark} block h-4 w-10 rounded-${config.track.rounded} shadow-inner outline-1 outline-transparent transition-all duration-${config.track.duration}`]:
{},
},
[`.${prefix}-switch-thin-single-label`]: {
[`@apply text-${config.singleLabel.text} relative ms-3 cursor-pointer select-none font-${config.singleLabel.font} text-${config.singleLabel.textSize}`]:
{},
},
[`.${prefix}-switch-dual-label`]: {
[`@apply ms-3`]: {},

[`.${prefix}-switch-label`]: {
[`@apply font-${config.dualLabel.label.font} text-${config.dualLabel.label.text} block text-${config.dualLabel.label.textSize} font-${config.dualLabel.label.fontWeight} dark:text-${config.dualLabel.label.textDark}`]:
{},
},
[`.${prefix}-switch-sublabel`]: {
[`@apply text-${config.dualLabel.sublabel.text} block font-${config.dualLabel.sublabel.font} text-${config.dualLabel.sublabel.textSize}`]:
{},
},
},
[`.${prefix}-switch-thin-input`]: {
[`@apply absolute z-20 h-${config.input.size} w-${config.input.size} cursor-pointer opacity-0`]:
{},

[`&:checked ~ .${prefix}-switch-thin-handle`]: {
[`@apply -translate-y-1/2 translate-x-full rtl:-translate-x-full`]:
{},
},
[`&:checked ~ .${prefix}-switch-thin-track`]: {
[`@apply outline-dashed outline-offset-2 ring-0 dark:outline-muted-600 outline-muted-300`]:
{},
},
},
[`&.${prefix}-switch-thin-primary .${prefix}-switch-thin-input:checked ~ .${prefix}-switch-thin-track`]:
{
[`@apply bg-${config.primary}`]: {},
},
[`&.${prefix}-switch-thin-info .${prefix}-switch-thin-input:checked ~ .${prefix}-switch-thin-track`]:
{
[`@apply bg-${config.info}`]: {},
},
[`&.${prefix}-switch-thin-success .${prefix}-switch-thin-input:checked ~ .${prefix}-switch-thin-track`]:
{
[`@apply bg-${config.success}`]: {},
},
[`&.${prefix}-switch-thin-warning .${prefix}-switch-thin-input:checked ~ .${prefix}-switch-thin-track`]:
{
[`@apply bg-${config.warning}`]: {},
},
[`&.${prefix}-switch-thin-danger .${prefix}-switch-thin-input:checked ~ .${prefix}-switch-thin-track`]:
{
[`@apply bg-${config.danger}`]: {},
},
},
})
}
},
function () {
return {
theme: {
shurikenUi: {
switchThin: defaultSwitchThinConfig,
},
},
}
}
)

0 comments on commit cac03fd

Please sign in to comment.