diff --git a/packages/daisyui/src/components/rating.css b/packages/daisyui/src/components/rating.css index 94c5ba18004..c2245273841 100644 --- a/packages/daisyui/src/components/rating.css +++ b/packages/daisyui/src/components/rating.css @@ -2,106 +2,89 @@ @layer daisyui.l1.l2.l3 { @apply relative inline-flex align-middle; - & input { - border: none; - @apply appearance-none; + --size: var(--size-selector, 0.25rem) * var(--rt-size-mul); + + input { + @apply cursor-pointer appearance-none; } - :where(*) { - @apply bg-base-content h-6 w-6 rounded-none opacity-20; + * { + @apply bg-base-content rounded-none opacity-20; + + width: calc(var(--size) * var(--rt-size-w-mul)); + height: calc(var(--size)); + @media (prefers-reduced-motion: no-preference) { animation: rating 0.25s ease-out; } - &:is(input) { - @apply cursor-pointer; - } } - & .rating-hidden { + .rating-hidden { @apply w-2 bg-transparent; } - input[type="radio"]:checked { - background-image: none; + :checked, + [aria-checked="true"], + [aria-current="true"], + :has(~ :checked, ~ [aria-checked="true"], ~ [aria-current="true"]) { + @apply opacity-100; } - * { - &:checked, - &[aria-checked="true"], - &[aria-current="true"], - &:has(~ *:checked, ~ *[aria-checked="true"], ~ *[aria-current="true"]) { - @apply opacity-100; - } - - &:focus-visible { - scale: 1.1; - @media (prefers-reduced-motion: no-preference) { - transition: scale 0.2s ease-out; - } + :focus-visible { + scale: 1.1; + @media (prefers-reduced-motion: no-preference) { + transition: scale 0.2s ease-out; } } - & *:active:focus { + :active:focus { animation: none; - } - - & *:active:focus { scale: 1.1; } } +} +.rating-half { @layer daisyui.l1.l2 { - &.rating-xs :where(*:not(.rating-hidden)) { - @apply size-4; - } - - &.rating-sm :where(*:not(.rating-hidden)) { - @apply size-5; - } - - &.rating-md :where(*:not(.rating-hidden)) { - @apply size-6; - } - - &.rating-lg :where(*:not(.rating-hidden)) { - @apply size-7; - } - - &.rating-xl :where(*:not(.rating-hidden)) { - @apply size-8; - } + --rt-size-w-mul: 0.5; } } -.rating-half { +.rating, +.rating-full { @layer daisyui.l1.l2 { - :where(*:not(.rating-hidden)) { - @apply w-3; - } + --rt-size-w-mul: 1; } } -.rating-half { +.rating-xs { @layer daisyui.l1.l2 { - &.rating-xs *:not(.rating-hidden) { - @apply w-2; - } + --rt-size-mul: 4; + } +} - &.rating-sm *:not(.rating-hidden) { - @apply w-2.5; - } +.rating-sm { + @layer daisyui.l1.l2 { + --rt-size-mul: 5; + } +} - &.rating-md *:not(.rating-hidden) { - @apply w-3; - } +.rating, +.rating-md { + @layer daisyui.l1.l2 { + --rt-size-mul: 6; + } +} - &.rating-lg *:not(.rating-hidden) { - @apply w-[.875rem]; - } +.rating-lg { + @layer daisyui.l1.l2 { + --rt-size-mul: 7; + } +} - &.rating-xl *:not(.rating-hidden) { - @apply w-4; - } +.rating-xl { + @layer daisyui.l1.l2 { + --rt-size-mul: 8; } } diff --git a/packages/docs/src/routes/(routes)/components/rating/+page.md b/packages/docs/src/routes/(routes)/components/rating/+page.md index 70113df8211..fea8e686b40 100644 --- a/packages/docs/src/routes/(routes)/components/rating/+page.md +++ b/packages/docs/src/routes/(routes)/components/rating/+page.md @@ -10,6 +10,8 @@ classnames: modifier: - class: rating-half desc: To shows half of the shapes. Useful for half star ratings + - class: rating-full + desc: To shows full shapes. Useful to override half star ratings - class: rating-hidden desc: For the first radio to make it hidden so user can clear the rating size: @@ -38,7 +40,7 @@ classnames: ### ~Rating