Skip to content

Commit

Permalink
feat(rating): small style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
acd02 committed Oct 24, 2023
1 parent 4a7858e commit 4b3c305
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/components/rating/src/Rating.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ const meta: Meta<typeof Rating> = {

export default meta

export const Default: StoryFn = _args => <Rating value={4.5} />
export const Default: StoryFn = _args => (
<div className="w-fit">
<Rating value={4.5} />
</div>
)
4 changes: 2 additions & 2 deletions packages/components/rating/src/Rating.styles.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { cx } from 'class-variance-authority'

export const ratingStyles = cx(
'inline-flex',
'flex',
'peer-[[data-part=input][data-clicked]]:shadow-none peer-focus-visible:u-ring',
'[&_[data-part=star]:hover_~_[data-part=star]_>_div]:!w-none' /* 1 */
)

/**
* 1. Display the remaining stars as outlined.
* By 'remaining,' we mean the stars located to the right of the cursor
* By 'remaining', we mean the stars located to the right of the cursor
*/
14 changes: 8 additions & 6 deletions packages/components/rating/src/Rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface RatingProps extends PropsWithChildren<ComponentPropsWithoutRef<
disabled?: boolean
}

// + intent, size

export const Rating = forwardRef<HTMLDivElement, RatingProps>(({ value, ...rest }, ref) => {
const [ratingValue, setRatingValue] = useState(value)
const inputRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -74,11 +72,17 @@ export const Rating = forwardRef<HTMLDivElement, RatingProps>(({ value, ...rest
}

return (
<div ref={ref} data-spark-component="rating" {...rest} onMouseLeave={resetDataPartStarAttr}>
<div
className="relative"
ref={ref}
data-spark-component="rating"
{...rest}
onMouseLeave={resetDataPartStarAttr}
>
<input
ref={inputRef}
data-part="input"
className="peer absolute opacity-0"
className="peer absolute inset-none opacity-0"
type="range"
min="0"
max="5"
Expand All @@ -100,8 +104,6 @@ export const Rating = forwardRef<HTMLDivElement, RatingProps>(({ value, ...rest
/>
))}
</div>

<span className="ml-xl">{ratingValue}</span>
</div>
)
})

0 comments on commit 4b3c305

Please sign in to comment.