Skip to content

Commit 685e996

Browse files
committed
feat(tailwind): add Rating component
1 parent c9904f5 commit 685e996

File tree

17 files changed

+432
-1
lines changed

17 files changed

+432
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Rating } from '@primereact/ui/rating';
2+
3+
const emojis = ['😡', '😕', '😐', '🙂', '😍'];
4+
5+
function EmojiDemo() {
6+
return (
7+
<div className="flex justify-center">
8+
<Rating.Root defaultValue={3} allowHalf={false}>
9+
{emojis.map((emoji, i) => (
10+
<Rating.Option key={i} index={i} className="!p-0 grayscale data-checked:grayscale-0 hover:grayscale-0 transition-all text-4xl select-none">
11+
<Rating.On />
12+
<Rating.Off>
13+
<span>{emoji}</span>
14+
</Rating.Off>
15+
</Rating.Option>
16+
))}
17+
</Rating.Root>
18+
</div>
19+
);
20+
}
21+
22+
export default EmojiDemo;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function AllowHalfDemo() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating defaultValue={3} allowHalf={false} />
8+
</div>
9+
);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function BasicDemo() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating defaultValue={3.5} />
8+
</div>
9+
);
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
import type { RatingRootValueChangeEvent } from 'primereact/rating';
4+
import * as React from 'react';
5+
6+
export default function ControlledDemo() {
7+
const [value, setValue] = React.useState<number | undefined>(4);
8+
9+
return (
10+
<div className="flex flex-col items-center justify-center gap-6">
11+
<Rating value={value} onValueChange={(e: RatingRootValueChangeEvent) => setValue(e.value)} />
12+
<div className="flex items-center gap-2">
13+
<button onClick={() => setValue(2.5)} className="px-3 py-1.5 text-sm rounded-md border border-surface-300 dark:border-surface-700 text-surface-700 dark:text-surface-0 hover:bg-surface-100 dark:hover:bg-surface-800 transition-colors">
14+
2.5 Star
15+
</button>
16+
<button onClick={() => setValue(3)} className="px-3 py-1.5 text-sm rounded-md border border-surface-300 dark:border-surface-700 text-surface-700 dark:text-surface-0 hover:bg-surface-100 dark:hover:bg-surface-800 transition-colors">
17+
3 Star
18+
</button>
19+
<button onClick={() => setValue(3.5)} className="px-3 py-1.5 text-sm rounded-md border border-surface-300 dark:border-surface-700 text-surface-700 dark:text-surface-0 hover:bg-surface-100 dark:hover:bg-surface-800 transition-colors">
20+
3.5 Star
21+
</button>
22+
</div>
23+
</div>
24+
);
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function DisabledDemo() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating value={3} disabled />
8+
</div>
9+
);
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Rating, RatingOff, RatingOn, RatingOption } from '@/components/ui/rating';
2+
3+
const emojis = ['😡', '😕', '😐', '🙂', '😍'];
4+
5+
export default function EmojiDemo() {
6+
return (
7+
<div className="flex justify-center">
8+
<Rating defaultValue={3} allowHalf={false}>
9+
{emojis.map((emoji, i) => (
10+
<RatingOption
11+
key={i}
12+
index={i}
13+
className="grayscale data-checked:grayscale-0 hover:grayscale-0 transition-all text-4xl select-none"
14+
>
15+
<RatingOn>
16+
<span>{emoji}</span>
17+
</RatingOn>
18+
<RatingOff>
19+
<span>{emoji}</span>
20+
</RatingOff>
21+
</RatingOption>
22+
))}
23+
</Rating>
24+
</div>
25+
);
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function Preview() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating defaultValue={3.5} />
8+
</div>
9+
);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function RatingPT() {
5+
return (
6+
<div className="flex items-center justify-center">
7+
<Rating defaultValue={3} />
8+
</div>
9+
);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function ReadOnlyDemo() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating value={3} readOnly />
8+
</div>
9+
);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client';
2+
import { Rating } from '@/components/ui/rating';
3+
4+
export default function StarsDemo() {
5+
return (
6+
<div className="flex justify-center">
7+
<Rating defaultValue={5} stars={10} />
8+
</div>
9+
);
10+
}

0 commit comments

Comments
 (0)