Skip to content
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(Rating, InfoRating): new components #1196

Merged
merged 20 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions playroom/snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3632,12 +3632,90 @@ const timerSnippets: Array<Snippet> = [
},
];

const ratingSnippets: Array<Snippet> = [
{
group: 'Rating',
name: 'InfoRating',
code: `
<InfoRating
aria-label="info rating"
size={24}
value={3}
count={6}
icon={{
ActiveIcon: IconStarFilled,
InactiveIcon: IconStarRegular,
color: skinVars.colors.warning,
marcoskolodny marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
`,
},
{
group: 'Rating',
name: 'Rating quantitative',
code: `
<Rating
aria-label="quantitative rating"
type="quantitative"
size={32}
defaultValue={3}
count={5}
icon={{
ActiveIcon: IconStarFilled,
InactiveIcon: IconStarRegular,
color: skinVars.colors.controlActivated,
}}
/>
`,
},
{
group: 'Rating',
name: 'Rating qualitative',
code: `
<Rating
aria-label="info rating"
marcoskolodny marked this conversation as resolved.
Show resolved Hide resolved
type="qualitative"
size={32}
valueLabels={["muy malo", "malo", "regular", "bueno", "muy bueno"]}
marcoskolodny marked this conversation as resolved.
Show resolved Hide resolved
icons={[
{
ActiveIcon: IconFaceSadFilled,
InactiveIcon: IconFaceSadRegular,
color: skinVars.colors.errorHigh,
},
{
ActiveIcon: IconFaceSlightlySadFilled,
InactiveIcon: IconFaceSlightlySadRegular,
color: skinVars.colors.error,
},
{
ActiveIcon: IconFaceNeutralFilled,
InactiveIcon: IconFaceNeutralRegular,
color: skinVars.colors.warning,
},
{
ActiveIcon: IconFaceHappyFilled,
InactiveIcon: IconFaceHappyRegular,
color: skinVars.colors.success,
},
{
ActiveIcon: IconFaceSuperHappyFilled,
InactiveIcon: IconFaceSuperHappyRegular,
color: skinVars.colors.successHigh,
},
]}
/>
`,
},
];

export default [
...buttonSnippets,
...formSnippets,
...feedbackSnippets,
...skeletonSnippets,
...timerSnippets,
...ratingSnippets,
{group: 'Feedbacks', name: 'Snackbar', code: '<Snackbar message="Some message here" />'},
...layoutSnippets,
{
Expand Down
Copy link
Collaborator Author

@marcoskolodny marcoskolodny Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore all changes related to icons. There is a another PR in which these changes are applied (#1197). I've updated them here because I needed some of the new icons.

Once the mentioned PR is merged, these changes will not be visible anymore here

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions src/__screenshot_tests__/rating-screenshot-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {openStoryPage, screen} from '../test-utils';

test.each([0, 1, 2, 3, 4, 5, 4.5, 4.51])('InfoRating - value = %s', async (value) => {
await openStoryPage({
id: 'components-rating--info-rating-story',
device: 'MOBILE_IOS',
args: {value},
});

const rating = await screen.findByTestId('info-rating');

expect(await rating.screenshot()).toMatchImageSnapshot();
});

test.each([4.5, 0.74, 0.75, 1.24, 4.25])('InfoRating - with half value and value = %s', async (value) => {
await openStoryPage({
id: 'components-rating--info-rating-story',
device: 'MOBILE_IOS',
args: {value, withHalfValue: true},
});

const rating = await screen.findByTestId('info-rating');

expect(await rating.screenshot()).toMatchImageSnapshot();
});

test.each([16, 24, 48])('InfoRating - size = %s', async (size) => {
await openStoryPage({
id: 'components-rating--info-rating-story',
device: 'MOBILE_IOS',
args: {size},
});

const rating = await screen.findByTestId('info-rating');

expect(await rating.screenshot()).toMatchImageSnapshot();
});

test('InfoRating - inverse', async () => {
await openStoryPage({
id: 'components-rating--info-rating-story',
device: 'MOBILE_IOS',
args: {inverse: true, value: 3},
});

const rating = await screen.findByTestId('info-rating');

expect(await rating.screenshot()).toMatchImageSnapshot();
});

test('Rating - quantitative', async () => {
const page = await openStoryPage({
id: 'components-rating--rating-story',
device: 'MOBILE_IOS',
args: {type: 'quantitative'},
});

const ratingWrapper = await screen.findByTestId('rating-wrapper');

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();

const thirdIcon = await screen.findByRole('radio', {name: '3 de 5'});
await page.click(thirdIcon);

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();
});

test('Rating - qualitative', async () => {
const page = await openStoryPage({
id: 'components-rating--rating-story',
device: 'MOBILE_IOS',
args: {type: 'qualitative'},
});

const ratingWrapper = await screen.findByTestId('rating-wrapper');

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();

const labels = ['muy malo', 'malo', 'regular', 'bueno', 'muy bueno'];

for (const label of labels) {
const currentIcon = await screen.findByRole('radio', {name: label});
await page.click(currentIcon);
expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();
}
});

test('Rating - qualitative inverse', async () => {
const page = await openStoryPage({
id: 'components-rating--rating-story',
device: 'MOBILE_IOS',
args: {type: 'qualitative', inverse: true},
});

const ratingWrapper = await screen.findByTestId('rating-wrapper');

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();

const thirdIcon = await screen.findByRole('radio', {name: 'regular'});
await page.click(thirdIcon);

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();
});

test.each([8, 24, 48])('Rating - size = %s', async (size) => {
await openStoryPage({
id: 'components-rating--rating-story',
device: 'MOBILE_IOS',
args: {size},
});

const ratingWrapper = await screen.findByTestId('rating-wrapper');

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();
});

test('Rating - inverse', async () => {
const page = await openStoryPage({
id: 'components-rating--rating-story',
device: 'MOBILE_IOS',
args: {inverse: true},
});

const ratingWrapper = await screen.findByTestId('rating-wrapper');

const thirdIcon = await screen.findByRole('radio', {name: '3 de 5'});
await page.click(thirdIcon);

expect(await ratingWrapper.screenshot()).toMatchImageSnapshot();
});
109 changes: 109 additions & 0 deletions src/__stories__/rating-story.tsx
marcoskolodny marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as React from 'react';
import {Box, InfoRating, Rating, ResponsiveLayout} from '..';

export default {
title: 'Components/Rating',
parameters: {fullScreen: true},
};

type RatingArgs = {
inverse: boolean;
count: number;
size: number;
type: 'quantitative' | 'qualitative';
disabled: boolean;
};

export const RatingStory: StoryComponent<RatingArgs> = ({inverse, count, size, type, disabled}) => {
return (
<ResponsiveLayout fullWidth isInverse={inverse}>
<Box padding={16}>
<div data-testid="rating-wrapper" style={{maxWidth: 'fit-content'}}>
<Rating
size={size}
disabled={disabled}
{...(type === 'qualitative'
? {type}
: {
type,
count,
})}
/>
</div>
</Box>
</ResponsiveLayout>
);
};

RatingStory.storyName = 'Rating';

RatingStory.args = {
type: 'quantitative',
count: 5,
size: 32,
disabled: false,
inverse: false,
};

RatingStory.argTypes = {
type: {
options: ['quantitative', 'qualitative'],
control: {type: 'select'},
},
count: {
control: {type: 'range', min: 1, max: 5},
if: {arg: 'type', eq: 'quantitative'},
},
size: {
control: {type: 'range', min: 16, max: 64, step: 4},
},
};

type InfoRatingArgs = {
inverse: boolean;
count: number;
value: number;
size: number;
withHalfValue: boolean;
};

export const InfoRatingStory: StoryComponent<InfoRatingArgs> = ({
inverse,
count,
value,
size,
withHalfValue,
}) => {
return (
<ResponsiveLayout fullWidth isInverse={inverse}>
<Box padding={16}>
<InfoRating
value={value}
count={count}
size={size}
withHalfValue={withHalfValue}
dataAttributes={{testid: 'info-rating'}}
/>
</Box>
</ResponsiveLayout>
);
};

InfoRatingStory.storyName = 'InfoRating';

InfoRatingStory.args = {
inverse: false,
withHalfValue: false,
count: 5,
size: 16,
value: 0,
};

InfoRatingStory.argTypes = {
count: {
control: {type: 'range', min: 1, max: 5},
},
size: {
control: {type: 'range', min: 16, max: 64, step: 4},
},
};
Loading
Loading