Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(radio): radio with tailwind forms #46

Merged
merged 16 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: addComponent for radio styles
  • Loading branch information
anuraghazra committed Jan 25, 2021
commit ebdc9269b86b74f699915779d7a9e1c7d85a8033
71 changes: 59 additions & 12 deletions forms.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
const svgToDataUri = require("mini-svg-data-uri");
const plugin = require("tailwindcss/plugin");
const defaultTheme = require("tailwindcss/defaultTheme");
const { colors } = defaultTheme;
const { colors, spacing, borderWidth, outline } = defaultTheme;

const forms = plugin(function ({ addBase, theme }) {
addBase({
[`[type='radio']:disabled`]: {
"border-width": "0px",
"background-color": theme("colors.gray.200", colors.gray[200]),
"background-image": `url("${svgToDataUri(
`<svg viewBox="0 0 16 16" fill="${theme(
"colors.gray.500",
colors.gray[500],
)}" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="3"/></svg>`,
)}")`,
const forms = plugin(function ({ addComponents, theme }) {
addComponents({
".custom-radio": {
appearance: "none",
padding: "0",
"color-adjust": "exact",
display: "inline-block",
"vertical-align": "middle",
"background-origin": "border-box",
"user-select": "none",
"flex-shrink": "0",
height: spacing[4],
width: spacing[4],
color: theme("colors.blue.600", colors.blue[600]),
"background-color": "#fff",
"border-color": theme("colors.gray.500", colors.gray[500]),
"border-width": borderWidth["DEFAULT"],
"border-radius": "100%",
"&:focus": {
outline: outline.none[0],
"outline-offset": outline.none[1],
"--tw-ring-inset": "var(--tw-empty,/*!*/ /*!*/)",
"--tw-ring-offset-width": "2px",
"--tw-ring-offset-color": "#fff",
"--tw-ring-color": theme("colors.blue.600", colors.blue[600]),
"--tw-ring-offset-shadow": `var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)`,
"--tw-ring-shadow": `var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color)`,
"box-shadow": `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000)`,
"border-color": theme("colors.gray.500", colors.gray[500]),
},
"&:checked": {
"border-color": `transparent`,
"background-color": `currentColor`,
"background-size": `100% 100%`,
"background-position": `center`,
"background-repeat": `no-repeat`,
"background-image": `url("${svgToDataUri(
`<svg viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="3"/></svg>`,
)}")`,
},
"&:checked:hover": {
"border-color": "transparent",
"background-color": "currentColor",
},
"&:checked:focus": {
"border-color": "transparent",
"background-color": "currentColor",
},
"&:disabled": {
"border-width": "0px",
"background-color": theme("colors.gray.200", colors.gray[200]),
"background-image": `url("${svgToDataUri(
`<svg viewBox="0 0 16 16" fill="${theme(
"colors.gray.500",
colors.gray[500],
)}" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="3"/></svg>`,
)}")`,
},
},
});
});
Expand Down
1 change: 0 additions & 1 deletion preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ const renderlesskitConfig = {
generateDataClassVariant("is-selection-end", true);
generateDataClassVariant("is-selection-end", true, "lib");
}),
require("@tailwindcss/forms"),
require("./forms"),
],
};
Expand Down
2 changes: 1 addition & 1 deletion src/theme/defaultTheme/radio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const radio = {
base: "lib:flex lib:items-center lib:gap-2",
input: "lib:text-gray-800",
input: "custom-radio lib:text-gray-800",
};