Skip to content

Commit

Permalink
feat: create modal plugin component (#24)
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 9d6e7c1 commit 4dd6aba
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,24 @@ export default withShurikenUI({
text: 'primary-800',
textDark: 'primary-200',
},
modal: {
backdrop: {
bg: 'muted-800/70',
bgDark: 'muted-900/80',
},
contentInner: {
space: '4',
},
contentPanel: {
size: 'full',
text: 'start',
},
modalSM: 'sm',
modalMD: 'md',
modalLG: 'xl',
modalXL: '2xl',
modal2XL: '3xl',
modal3XL: '5xl',
paragraph: {
textXS: 'xs',
textSM: 'sm',
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 @@ -24,6 +24,7 @@ import link from './link'
import listbox from './listbox'
import mark from './mark'
import mask from './mask'
import modal from './modal'
import paragraph from './paragraph'
import message from './message'
import placeload from './placeload'
Expand Down Expand Up @@ -66,6 +67,7 @@ const components = [
listbox,
mark,
mask,
modal,
paragraph,
message,
placeload,
Expand Down
100 changes: 100 additions & 0 deletions src/plugins/components/modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import plugin from 'tailwindcss/plugin'
import { defu } from 'defu'
import { type PluginOption, defaultPluginOptions } from '../options'

const defaultModalConfig = {
backdrop: {
bg: 'muted-800/70',
bgDark: 'muted-900/80',
},
contentInner: {
space: '4',
},
contentPanel: {
size: 'full',
text: 'start',
},
modalSM: 'sm',
modalMD: 'md',
modalLG: 'xl',
modalXL: '2xl',
modal2XL: '3xl',
modal3XL: '5xl',
}

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

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

addComponents({
[`.${prefix}-modal`]: {
[`@apply fixed inset-0 z-[9999] flex items-center justify-center`]:
{},

[`.${prefix}-modal-inner`]: {
[`@apply relative z-[9999]`]: {},
},
[`.${prefix}-modal-backdrop`]: {
[`@apply bg-${config.backdrop.bg} dark:bg-${config.backdrop.bgDark} fixed inset-0`]:
{},
},
[`.${prefix}-modal-content`]: {
[`@apply fixed inset-0`]: {},
},
[`.${prefix}-modal-content-inner`]: {
[`@apply flex w-full min-h-full items-center justify-center p-${config.contentInner.space} text-center`]:
{},
},
[`.${prefix}-modal-content-panel`]: {
[`@apply w-${config.contentPanel.size} text-${config.contentPanel.text} align-middle transition-all`]:
{},
},
[`&.${prefix}-modal-sm`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modalSM}`]: {},
},
},
[`&.${prefix}-modal-md`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modalMD}`]: {},
},
},
[`&.${prefix}-modal-lg`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modalLG}`]: {},
},
},
[`&.${prefix}-modal-xl`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modalXL}`]: {},
},
},
[`&.${prefix}-modal-2xl`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modal2XL}`]: {},
},
},
[`&.${prefix}-modal-3xl`]: {
[`.${prefix}-modal-content-panel`]: {
[`@apply max-w-${config.modal3XL}`]: {},
},
},
},
})
}
},
function () {
return {
theme: {
shurikenUi: {
modal: defaultModalConfig,
},
},
}
}
)

0 comments on commit 4dd6aba

Please sign in to comment.