-
Notifications
You must be signed in to change notification settings - Fork 266
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(web-core): added UiRadioButton component #8067
base: master
Are you sure you want to change the base?
Conversation
c36f179
to
4a4bfa5
Compare
72a1f84
to
41482b8
Compare
@xen-orchestra/lite/src/stories/web-core/ui/radio-button/ui-radio-button.story.vue
Outdated
Show resolved
Hide resolved
@xen-orchestra/lite/src/stories/web-core/ui/radio-button/ui-radio-button.story.vue
Outdated
Show resolved
Hide resolved
@xen-orchestra/web-core/lib/components/ui/radio-button/UiRadioButton.vue
Outdated
Show resolved
Hide resolved
41482b8
to
c9a8f11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code can be simplified a lot here.
Also, the icon seems misaligned (it should look like the bottom version):
Finally, I don't think the info slot should be part of the Radio component. When looking at the DS, it seems that it rather belongs to the Radio Group component.
Here is a suggestion:
<template>
<label class="ui-radio-button typo p1-regular">
<span :class="variant" class="radio-container">
<input v-model="model" :disabled="isDisabled" :value class="input" type="radio" />
<VtsIcon :icon="faCircle" accent="current" class="radio-icon" />
</span>
<slot />
</label>
</template>
<script lang="ts" setup>
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import { useContext } from '@core/composables/context.composable'
import { DisabledContext } from '@core/context'
import { toVariants } from '@core/utils/to-variants.util'
import { faCircle } from '@fortawesome/free-solid-svg-icons'
import { computed } from 'vue'
const props = withDefaults(
defineProps<{
accent: 'info' | 'success' | 'warning' | 'danger'
value: any
disabled?: boolean
}>(),
{
disabled: undefined,
}
)
const model = defineModel<boolean>()
defineSlots<{
default(): any
}>()
const variant = computed(() => toVariants({ accent: props.accent }))
const isDisabled = useContext(DisabledContext, () => props.disabled)
</script>
<style lang="postcss" scoped>
.ui-radio-button {
display: inline-flex;
align-items: center;
gap: 0.8rem;
.radio-container {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0.2rem solid var(--accent-color);
background-color: transparent;
border-radius: 0.8rem;
width: 1.6rem;
height: 1.6rem;
transition:
border-color 0.125s ease-in-out,
background-color 0.125s ease-in-out;
&:has(.input:disabled) {
cursor: not-allowed;
/*
TODO: To be removed or kept after a decision has been taken
See https://www.figma.com/design/l2O2VvzJRnOCvqxhM7d124?node-id=8-1940#1021964394
*/
&:not(:has(.input:checked)) {
--accent-color: var(--color-neutral-txt-secondary);
}
}
&:has(.input:checked) {
background-color: var(--accent-color);
}
&.accent--info {
--accent-color: var(--color-info-item-base);
&:hover {
--accent-color: var(--color-info-item-hover);
}
&:active {
--accent-color: var(--color-info-item-active);
}
&:has(.input:disabled) {
--accent-color: var(--color-info-item-disabled);
}
}
&.accent--success {
--accent-color: var(--color-success-item-base);
&:hover {
--accent-color: var(--color-success-item-hover);
}
&:active {
--accent-color: var(--color-success-item-active);
}
&:has(.input:disabled) {
--accent-color: var(--color-success-item-disabled);
}
}
&.accent--warning {
--accent-color: var(--color-warning-item-base);
&:hover {
--accent-color: var(--color-warning-item-hover);
}
&:active {
--accent-color: var(--color-warning-item-active);
}
&:has(.input:disabled) {
--accent-color: var(--color-warning-item-disabled);
}
}
&.accent--danger {
--accent-color: var(--color-danger-item-base);
&:hover {
--accent-color: var(--color-danger-item-hover);
}
&:active {
--accent-color: var(--color-danger-item-active);
}
&:has(.input:disabled) {
--accent-color: var(--color-danger-item-disabled);
}
}
/* INPUT */
.input {
opacity: 0;
position: absolute;
pointer-events: none;
}
/* ICON */
.radio-icon {
font-size: 0.8rem;
position: absolute;
opacity: 0;
transition: opacity 0.125s ease-in-out;
color: var(--color-neutral-txt-primary);
}
&.accent--danger .radio-icon {
color: var(--color-danger-txt-item);
}
.input:disabled + .radio-icon {
color: var(--color-neutral-txt-secondary);
}
.input:checked + .radio-icon {
opacity: 1;
}
}
}
</style>
@ByScripts Are you sure for the info slot ? because if you look there it appears to be for both components (even though there is a checkbox that appears to be a copy and paste of the checkbox component). Maybe we can ask to @clemencebx ? |
Yes, I think we should wait for @clemencebx because I don't think it would make sense to have an individual message for each input 🤔 IMO, in case we want to add a specific "help" for an input, it should probably be through an "Info" icon next to the label. Edit: Link to Figma comment |
Yes, I agree with you ! |
|
b1dcb42
to
b2d1d88
Compare
Checkbox + Label:
Radiobox + Label:
Does this structure work for you? If so, I’ll update the Figma documentation accordingly to reduce any confusion. |
27511c5
to
789efe4
Compare
.radio-container .radio-icon { | ||
color: var(--color-danger-txt-item); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this selector can be simplified to:
.radio-container .radio-icon { | |
color: var(--color-danger-txt-item); | |
} | |
.radio-icon { | |
color: var(--color-danger-txt-item); | |
} |
And it should be used in the other accent variants with the right values, since the icon color also changes for info
, success
and warning
. Here is a screenshot of the design system; we can see the value is --color-info-txt-item
for the info
variant:
789efe4
to
fc21f5f
Compare
Description
Added UiRadioButton component
Screeshot
Checklist
Fixes #007
,See xoa-support#42
,See https://...
)Introduced by
CHANGELOG.unreleased.md
Review process
Notes: