-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update playground radio components
- Loading branch information
Showing
4 changed files
with
203 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
<script setup lang="ts"> | ||
import { RadioProps, useRadio } from '@formwerk/core'; | ||
import { type RadioProps, useRadio } from '@formwerk/core'; | ||
const props = defineProps<RadioProps>(); | ||
const { labelProps, inputProps } = useRadio(props); | ||
</script> | ||
|
||
<template> | ||
<div class="flex items-center"> | ||
<input v-bind="inputProps" /> | ||
<div class="radio-item"> | ||
<label v-bind="labelProps"> | ||
<input v-bind="inputProps" class="sr-only" /> | ||
|
||
<label v-bind="labelProps" class="ml-1">{{ label }}</label> | ||
{{ label }} | ||
</label> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
:root { | ||
--color-text: #333; | ||
--color-hint: #666; | ||
--color-border: #ccc; | ||
--color-focus: #0056b3; | ||
--color-error: #f00; | ||
--color-valid: #059669; | ||
--color-hover: #eee; | ||
} | ||
</style> | ||
|
||
<style scoped> | ||
.radio-item { | ||
display: inline-flex; | ||
align-items: center; | ||
border-radius: 99999px; | ||
padding: 0.5rem 1rem; | ||
border: 1px solid var(--color-border); | ||
font-size: 13px; | ||
font-weight: 500; | ||
transition: | ||
background-color 0.15s, | ||
color 0.15s; | ||
&:has(:focus) { | ||
border: 1px solid var(--color-focus); | ||
} | ||
&:has(:checked) { | ||
background-color: var(--color-focus); | ||
color: #fff; | ||
} | ||
} | ||
/** This is a common utility CSS class, you can find it in your CSS framework of choice */ | ||
.sr-only { | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
padding: 0; | ||
margin: -1px; | ||
overflow: hidden; | ||
clip: rect(0, 0, 0, 0); | ||
border: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,90 @@ | ||
<script setup lang="ts"> | ||
import { RadioGroupProps, useRadioGroup } from '@formwerk/core'; | ||
import { type RadioGroupProps, useRadioGroup } from '@formwerk/core'; | ||
const props = defineProps<RadioGroupProps>(); | ||
const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, errorMessage } = useRadioGroup(props); | ||
const { groupProps, labelProps, descriptionProps, errorMessageProps, errorMessage, fieldValue } = useRadioGroup(props); | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-bind="radioGroupProps" | ||
class="flex border border-gray-200 rounded-md p-2 gap-1" | ||
:class="{ 'flex-col': orientation === 'vertical' }" | ||
> | ||
<span v-bind="labelProps" class="font-medium">{{ label }}</span> | ||
<div v-bind="groupProps" class="radio-group"> | ||
<div v-bind="labelProps" class="group-label">{{ label }} {{ fieldValue }}</div> | ||
|
||
<slot /> | ||
<div class="radios-container"> | ||
<slot /> | ||
</div> | ||
|
||
<div v-if="errorMessageProps" v-bind="errorMessageProps" class="text-red-500 text-xs">{{ errorMessage }}</div> | ||
<div v-if="errorMessage" v-bind="errorMessageProps" class="error"> | ||
{{ errorMessage }} | ||
</div> | ||
|
||
<div v-else-if="description" v-bind="descriptionProps" class="text-gray-500 text-xs">{{ description }}</div> | ||
<div v-else-if="description" v-bind="descriptionProps" class="hint"> | ||
{{ description }} | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
:root { | ||
--color-text: #333; | ||
--color-hint: #666; | ||
--color-border: #ccc; | ||
--color-focus: #007bff; | ||
--color-error: #f00; | ||
--color-valid: #059669; | ||
--color-hover: #eee; | ||
} | ||
</style> | ||
|
||
<style scoped> | ||
.radio-group { | ||
display: flex; | ||
flex-direction: column; | ||
.hint, | ||
.error { | ||
margin-top: 0.25rem; | ||
} | ||
.error { | ||
color: var(--color-error); | ||
display: none; | ||
font-size: 13px; | ||
} | ||
.hint { | ||
color: var(--color-hint); | ||
font-size: 13px; | ||
opacity: 0; | ||
transition: opacity 0.3s ease; | ||
} | ||
.radios-container { | ||
margin-top: 0.25rem; | ||
} | ||
.group-label { | ||
color: var(--color-text); | ||
display: block; | ||
margin-bottom: 0.25rem; | ||
font-size: 14px; | ||
font-weight: 500; | ||
} | ||
&:has(:focus) { | ||
.hint { | ||
opacity: 1; | ||
} | ||
} | ||
&:has(:invalid) { | ||
.error { | ||
display: block; | ||
} | ||
.hint { | ||
display: none; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,63 @@ | ||
<script setup lang="ts"> | ||
import { RadioProps, useRadio } from '@formwerk/core'; | ||
import { type RadioProps, useRadio } from '@formwerk/core'; | ||
const props = defineProps<RadioProps>(); | ||
const { labelProps, radioProps, isChecked } = useRadio(props); | ||
const { labelProps, inputProps } = useRadio(props); | ||
</script> | ||
|
||
<template> | ||
<div v-bind="radioProps" class="flex items-center"> | ||
<div | ||
class="w-5 h-5 rounded-full flex-shrink-0 border border-gray-600 flex items-center justify-center focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" | ||
> | ||
<div class="w-3 h-3 rounded-full flex-shrink-0" :class="{ 'bg-blue-500': isChecked }" /> | ||
<div class="radio-item" v-bind="inputProps"> | ||
<div v-bind="labelProps"> | ||
{{ label }} | ||
</div> | ||
|
||
<span v-bind="labelProps" class="ml-1">{{ label }}</span> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
:root { | ||
--color-text: #333; | ||
--color-hint: #666; | ||
--color-border: #ccc; | ||
--color-focus: #0056b3; | ||
--color-error: #f00; | ||
--color-valid: #059669; | ||
--color-hover: #eee; | ||
} | ||
</style> | ||
|
||
<style scoped> | ||
.radio-item { | ||
display: inline-flex; | ||
align-items: center; | ||
border-radius: 99999px; | ||
padding: 0.5rem 1rem; | ||
border: 1px solid var(--color-border); | ||
font-size: 13px; | ||
font-weight: 500; | ||
transition: | ||
background-color 0.15s, | ||
color 0.15s; | ||
&:focus { | ||
border: 1px solid var(--color-focus); | ||
} | ||
&[aria-checked='true'] { | ||
background-color: var(--color-focus); | ||
color: #fff; | ||
} | ||
} | ||
/** This is a common utility CSS class, you can find it in your CSS framework of choice */ | ||
.sr-only { | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
padding: 0; | ||
margin: -1px; | ||
overflow: hidden; | ||
clip: rect(0, 0, 0, 0); | ||
border: 0; | ||
} | ||
</style> |