diff --git a/packages/tailwindcss/index.js b/packages/tailwindcss/index.js index ef21cbfe..548628c7 100644 --- a/packages/tailwindcss/index.js +++ b/packages/tailwindcss/index.js @@ -2,6 +2,16 @@ const button = require("./button"); const outlinedButton = require("./outlinedButton"); const status = require("./status"); const card = require("./card"); -const form = require("./form"); +const input = require("./input"); +const select = require("./select"); +const toggleSwitch = require("./toggleSwitch"); -module.exports = [button, outlinedButton, status, card, form]; +module.exports = [ + button, + outlinedButton, + status, + card, + input, + select, + toggleSwitch, +]; diff --git a/packages/tailwindcss/form.js b/packages/tailwindcss/input.js similarity index 65% rename from packages/tailwindcss/form.js rename to packages/tailwindcss/input.js index de772b97..7848662d 100644 --- a/packages/tailwindcss/form.js +++ b/packages/tailwindcss/input.js @@ -6,14 +6,6 @@ module.exports = plugin.withOptions( () => { return ({ addComponents, theme }) => { addComponents([ - { - ".label": { - color: theme("colors.gray.600"), - fontSize: "12px", - lineHeight: 1, - marginBottom: "1em", - }, - }, { "[type='text'],[type='email'],[type='url'],[type='password'],[type='number'],[type='date'],[type='datetime-local'],[type='month'],[type='search'],[type='tel'],[type='time'],[type='week'],[multiple],textarea,select": { appearance: "none", @@ -117,76 +109,6 @@ module.exports = plugin.withOptions( outline: `1px auto -webkit-focus-ring-color`, }, }, - select: { - "background-image": `url("${svgToDataUri( - `` - )}")`, - "background-position": `right ${theme("spacing.2")} center`, - "background-repeat": `no-repeat`, - "background-size": `1.5em 1.5em`, - "padding-right": theme("spacing.10"), - "color-adjust": `exact`, - }, - "[multiple]": { - "background-image": "initial", - "background-position": "initial", - "background-repeat": "unset", - "background-size": "initial", - "padding-right": theme("spacing.3"), - "color-adjust": "unset", - }, - }, - { - ".switch": { - position: "relative", - width: theme("spacing.16"), - height: theme("spacing.8"), - input: { - position: "absolute", - left: 0, - top: 0, - width: "100%", - height: "100%", - "z-index": 5, - opacity: 0, - cursor: "pointer", - }, - - label: { - width: theme("width.full"), - height: theme("height.full"), - background: theme("colors.gray.300"), - position: "relative", - display: "inline-block", - "border-radius": theme("borderRadius.full"), - transition: "0.2s", - "box-sizing": "border-box", - span: { - content: "", - position: "absolute", - width: theme("spacing.8"), - height: theme("height.full"), - "border-radius": "100%", - left: 0, - top: 0, - "z-index": 2, - background: theme("colors.white"), - "box-shadow": "0 0 5px rgba(0, 0, 0, 0.2)", - transition: "0.2s", - }, - }, - - "input:checked": { - "+label": { - "background-color": theme("colors.primary.500"), - span: { - transform: "translateX(100%)", - }, - }, - }, - }, }, ]); }; diff --git a/packages/tailwindcss/select.js b/packages/tailwindcss/select.js new file mode 100644 index 00000000..070b94a6 --- /dev/null +++ b/packages/tailwindcss/select.js @@ -0,0 +1,35 @@ +const plugin = require("tailwindcss/plugin"); +const theme = require("./theme"); +const svgToDataUri = require("mini-svg-data-uri"); + +module.exports = plugin.withOptions( + () => { + return ({ addComponents, theme }) => { + addComponents([ + { + select: { + "background-image": `url("${svgToDataUri( + `` + )}")`, + "background-position": `right ${theme("spacing.2")} center`, + "background-repeat": `no-repeat`, + "background-size": `1.5em 1.5em`, + "padding-right": theme("spacing.10"), + "color-adjust": `exact`, + }, + "[multiple]": { + "background-image": "initial", + "background-position": "initial", + "background-repeat": "unset", + "background-size": "initial", + "padding-right": theme("spacing.3"), + "color-adjust": "unset", + }, + }, + ]); + }; + }, + () => ({ theme }) +); diff --git a/packages/tailwindcss/stories/Button.stories.js b/packages/tailwindcss/stories/Button.stories.js index 4b96cd91..b1305c03 100644 --- a/packages/tailwindcss/stories/Button.stories.js +++ b/packages/tailwindcss/stories/Button.stories.js @@ -2,25 +2,17 @@ export default { title: "Buttons/Button", argTypes: { label: { control: "text" }, + disabled: { control: "boolean" }, }, }; -const Template = ({ label }) => { - return ``; +const Template = ({ label, disabled }) => { + return ``; }; export const Default = Template.bind({}); Default.args = { label: "ボタン", }; - -const disabledTemplate = ({ label }) => { - return ` - - `; -}; - -export const Disabled = disabledTemplate.bind({}); -Disabled.args = { - ...Default.args, -}; diff --git a/packages/tailwindcss/stories/Input.stories.js b/packages/tailwindcss/stories/Input.stories.js index a226b60a..7e9d586e 100644 --- a/packages/tailwindcss/stories/Input.stories.js +++ b/packages/tailwindcss/stories/Input.stories.js @@ -69,36 +69,3 @@ const FileTemplate = () => { return ``; }; export const File = FileTemplate.bind({}); - -const SelectTemplate = () => { - return ` - - `; -}; -export const Select = SelectTemplate.bind({}); - -const SelectMultipleTemplate = () => { - return ` - - `; -}; -export const SelectMultiple = SelectMultipleTemplate.bind({}); - -const SwitchTemplate = () => { - return ` -
- -
- `; -}; -export const Switch = SwitchTemplate.bind({}); diff --git a/packages/tailwindcss/stories/Select.stories.js b/packages/tailwindcss/stories/Select.stories.js new file mode 100644 index 00000000..687f50b4 --- /dev/null +++ b/packages/tailwindcss/stories/Select.stories.js @@ -0,0 +1,25 @@ +export default { + title: "Forms/Select", +}; + +const SelectTemplate = () => { + return ` + + `; +}; +export const Select = SelectTemplate.bind({}); + +const SelectMultipleTemplate = () => { + return ` + + `; +}; +export const SelectMultiple = SelectMultipleTemplate.bind({}); diff --git a/packages/tailwindcss/stories/ToggleSwitch.stories.js b/packages/tailwindcss/stories/ToggleSwitch.stories.js new file mode 100644 index 00000000..58a41cf1 --- /dev/null +++ b/packages/tailwindcss/stories/ToggleSwitch.stories.js @@ -0,0 +1,14 @@ +export default { + title: "Forms/ToggleSwitch", +}; + +const ToggleSwitchTemplate = () => { + return ` +
+ +
+ `; +}; +export const Default = ToggleSwitchTemplate.bind({}); diff --git a/packages/tailwindcss/toggleSwitch.js b/packages/tailwindcss/toggleSwitch.js new file mode 100644 index 00000000..97006ab3 --- /dev/null +++ b/packages/tailwindcss/toggleSwitch.js @@ -0,0 +1,62 @@ +const plugin = require("tailwindcss/plugin"); +const theme = require("./theme"); + +module.exports = plugin.withOptions( + () => { + return ({ addComponents, theme }) => { + addComponents([ + { + ".switch": { + position: "relative", + width: theme("spacing.16"), + height: theme("spacing.8"), + input: { + position: "absolute", + left: 0, + top: 0, + width: "100%", + height: "100%", + "z-index": 5, + opacity: 0, + cursor: "pointer", + }, + + label: { + width: theme("width.full"), + height: theme("height.full"), + background: theme("colors.gray.300"), + position: "relative", + display: "inline-block", + "border-radius": theme("borderRadius.full"), + transition: "0.2s", + "box-sizing": "border-box", + span: { + content: "", + position: "absolute", + width: theme("spacing.8"), + height: theme("height.full"), + "border-radius": "100%", + left: 0, + top: 0, + "z-index": 2, + background: theme("colors.white"), + "box-shadow": "0 0 5px rgba(0, 0, 0, 0.2)", + transition: "0.2s", + }, + }, + + "input:checked": { + "+label": { + "background-color": theme("colors.primary.500"), + span: { + transform: "translateX(100%)", + }, + }, + }, + }, + }, + ]); + }; + }, + () => ({ theme }) +);