Skip to content

Commit

Permalink
feat(radioButton): initial styling for radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasphil committed Sep 9, 2024
1 parent ec3b41a commit e77c6a0
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/primevue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import inputGroup from "./inputGroup/inputGroup";
import inputGroupAddon from "./inputGroup/inputGroupAddon";
import inputText from "./inputText/inputText";
import password from "./password/password";
import radioButton from "./radioButton/radioButton";

export const RisUiTheme = {
button,
inputText,
inputGroup,
inputGroupAddon,
password,
radioButton,
};
133 changes: 133 additions & 0 deletions src/primevue/radioButton/radioButton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { html } from "@/lib/tags.ts";
import { Meta, StoryObj } from "@storybook/vue3";
import RadioButton from "primevue/radiobutton";
import { ref } from "vue";

const meta: Meta<typeof RadioButton> = {
component: RadioButton,

tags: ["autodocs"],

args: {
disabled: false,
invalid: false,
},
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
render: (args) => ({
components: { RadioButton },
setup() {
const checked = ref("");
return { args, checked };
},
template: html`<RadioButton
v-bind="args"
v-model="checked"
name="radio"
value="radio"
/>`,
}),
};

export const WithLabel: Story = {
render: (args) => ({
components: { RadioButton },
setup() {
const checked = ref("radio");
return { args, checked };
},
template: html`
<div class="flex items-center">
<RadioButton
input-id="radio-with-label"
v-bind="args"
v-model="checked"
name="radio"
value="radio"
/>
<label for="radio-with-label">Radio with label</label>
</div>
`,
}),
};

export const Group: Story = {
render: (args) => ({
components: { RadioButton },
setup() {
const checked = ref("radio-1");
return { args, checked };
},
template: html`
<div class="flex gap-32">
<div class="flex items-center">
<RadioButton
input-id="radio-1"
v-model="checked"
name="radios"
value="radio-1"
/>
<label for="radio-1">One</label>
</div>
<div class="flex items-center">
<RadioButton
input-id="radio-2"
v-model="checked"
name="radios"
value="radio-2"
/>
<label for="radio-2">Two</label>
</div>
<div class="flex items-center">
<RadioButton
input-id="radio-3"
v-model="checked"
name="radios"
value="radio-3"
/>
<label for="radio-3">Three</label>
</div>
<div class="flex items-center">
<RadioButton
input-id="radio-4"
v-model="checked"
name="radios"
value="radio-4"
/>
<label for="radio-4">Four</label>
</div>
</div>
`,
}),
};

export const WithErrorMessage: Story = {
args: {
invalid: true,
},

render: (args) => ({
components: { RadioButton },
setup() {
const checked = ref("");
return { args, checked };
},
template: html`
<div class="mb-4 flex items-center">
<RadioButton
input-id="radio-with-error"
v-bind="args"
v-model="checked"
name="radio"
value="radio"
/>
<label for="radio-with-error">Radio with label</label>
</div>
<span class="ris-body2-regular text-red-800">Error description</span>
`,
}),
};
22 changes: 22 additions & 0 deletions src/primevue/radioButton/radioButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { tw } from "@/lib/tags";
import { RadioButtonPassThroughOptions } from "primevue/radiobutton";

const radioButton: RadioButtonPassThroughOptions = {
root: {
class: tw`relative inline-block h-32 w-32 [&+label]:ris-label2-regular [&+label]:ml-8`,
},

input: {
class: tw`peer h-full w-full cursor-pointer appearance-none rounded-full border-2 border-blue-800 bg-white outline-4 -outline-offset-4 outline-blue-800 hover:outline focus:outline active:outline-none disabled:cursor-not-allowed disabled:border-gray-600 disabled:outline-none aria-[invalid]:border-red-800 aria-[invalid]:outline-red-800 aria-[invalid]:active:outline-none aria-[invalid]:disabled:outline-none`,
},

box: {
class: tw`pointer-events-none absolute inset-0 flex items-center justify-center text-transparent peer-checked:text-blue-800 peer-disabled:text-gray-600 peer-aria-[invalid]:text-red-800`,
},

icon: {
class: tw`h-16 w-16 rounded-full bg-current`,
},
};

export default radioButton;

0 comments on commit e77c6a0

Please sign in to comment.