Skip to content
Merged
2 changes: 2 additions & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export { default as RadioGroup, RadioOption } from './molecules/RadioGroup'
export type { RadioGroupProps, RadioOptionProps } from './molecules/RadioGroup'
export { default as Rating } from './molecules/Rating'
export type { RatingProps } from './molecules/Rating'
export { default as RatingField } from './molecules/RatingField'
export type { RatingFieldProps } from './molecules/RatingField'
export { default as RegionBar } from './molecules/RegionBar'
export type { RegionBarProps } from './molecules/RegionBar'

Expand Down
71 changes: 71 additions & 0 deletions packages/components/src/molecules/RatingField/RatingField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react'
import type { MutableRefObject } from 'react'
import { Label, Rating, type RatingProps } from '../..'

interface DefaultProps {
/**
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
*/
testId?: string
/**
* ID to identify input and corresponding label.
*/
id: string
/**
* The text displayed to identify the input rating.
*/
label: string
/**
* The error message displayed when an error occurs.
*/
error?: string
/**
* Component's ref.
*/
ratingRef?: MutableRefObject<HTMLUListElement | null>
}

export type RatingFieldProps = DefaultProps & RatingProps

const RatingField = ({
id,
label,
error,
disabled,
length = 5,
value = 0,
onChange,
ratingRef,
testId = 'fs-rating-field',
...otherProps
}: RatingFieldProps) => {
const shouldDisplayError = !disabled && error && error !== ''

return (
<div
data-fs-rating-field
data-fs-rating-field-error={shouldDisplayError}
data-fs-rating-field-disabled={disabled}
data-testid={testId}
>
<Label data-fs-rating-field-label htmlFor={id}>
{label}
</Label>
<Rating
id={id}
data-fs-rating-field-input
ref={ratingRef}
length={length}
value={value}
onChange={onChange}
disabled={disabled}
{...otherProps}
/>
{shouldDisplayError && (
<span data-fs-rating-field-error-message>{error}</span>
)}
</div>
)
}

export default RatingField
2 changes: 2 additions & 0 deletions packages/components/src/molecules/RatingField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './RatingField'
export type { RatingFieldProps } from './RatingField'
11 changes: 5 additions & 6 deletions packages/ui/src/components/molecules/Rating/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// --------------------------------------------------------
// Structural Styles
// --------------------------------------------------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

todo: fix the button size, it's currently 48px, and should be 32px.

image

I will suggest adding a new token:

// Button
--fs-rating-button-min-height: var(--fs-spacing-5);

and then on line 34, force the size:

[data-fs-rating-button] {
 --fs-button-small-min-height: var(--fs-rating-button-min-height);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've implemented the suggested change, I had previously kept the token value because I thought it was something set for accessibility, so as not to make the touch area so small

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, it is! In this case, I believe the design team considers 24px as the minimum target size. @renatamottam

display: flex;

[data-fs-icon] {
Expand All @@ -32,15 +33,12 @@

[data-fs-rating-button] {
color: unset;

&[disabled] [data-fs-button-wrapper] {
background-color: transparent;

&:hover {
background-color: transparent;
}
}

&[data-fs-button-variant="tertiary"]:hover,
&[data-fs-button-variant="tertiary"]:focus,
&[data-fs-button-variant="tertiary"]:active {
Expand Down Expand Up @@ -73,15 +71,15 @@
fill: none;
}

[data-fs-rating-item="partial"] [data-fs-rating-icon-wrapper] {
[data-fs-rating-item='partial'] [data-fs-rating-icon-wrapper] {
width: calc(var(--fs-rating-icon-width) / 2);
}

&:not([data-fs-rating-actionable="true"]) {
&:not([data-fs-rating-actionable='true']) {
column-gap: var(--fs-rating-gap);
}

&[data-fs-rating-actionable="true"] {
&[data-fs-rating-actionable='true'] {
column-gap: var(--fs-rating-actionable-gap);

[data-fs-rating-item="full"] svg[data-fs-icon] {
Expand All @@ -90,6 +88,7 @@
}

[data-fs-icon] {
color: var(--fs-rating-actionable-color);
width: var(--fs-rating-actionable-icon-width);
height: var(--fs-rating-actionable-icon-height);
color: var(--fs-rating-actionable-icon-color);
Expand Down
42 changes: 42 additions & 0 deletions packages/ui/src/components/molecules/RatingField/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[data-fs-rating-field] {
// --------------------------------------------------------
// Design Tokens for Rating Field
// --------------------------------------------------------

Comment thread
hellofanny marked this conversation as resolved.
// Label
--fs-rating-field-label-color: var(--fs-color-text-light);
--fs-rating-field-label-size: var(--fs-text-size-2);
--fs-rating-field-label-line-height: var(--fs-text-size-4);

// Error
--fs-rating-field-error-message-size: var(--fs-text-size-legend);
--fs-rating-field-error-message-line-height: 1.1;
--fs-rating-field-error-message-color: var(--fs-color-danger-text);

// --------------------------------------------------------
// Structural Styles
// --------------------------------------------------------
display: flex;
flex-direction: column;

[data-fs-rating-field-label] {
font-size: var(--fs-rating-field-label-size);
Comment thread
hellofanny marked this conversation as resolved.
line-height: var(--fs-rating-field-label-line-height);
color: var(--fs-rating-field-label-color);
}

[data-fs-rating-field-error-message] {
font-size: var(--fs-rating-field-error-message-size);
Comment thread
hellofanny marked this conversation as resolved.
line-height: var(--fs-rating-field-error-message-line-height);
color: var(--fs-rating-field-error-message-color);
}

// --------------------------------------------------------
// Variants Styles
// --------------------------------------------------------
&[data-fs-rating-field-error="true"] {
[data-fs-rating-item="empty"] [data-fs-icon] {
color: var(--fs-rating-field-error-message-color);
}
}
}
1 change: 1 addition & 0 deletions packages/ui/src/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@import "../components/molecules/QuantitySelector/styles";
@import "../components/molecules/RadioField/styles";
@import "../components/molecules/Rating/styles";
@import "../components/molecules/RatingField/styles";
@import "../components/molecules/RegionBar/styles";
@import "../components/molecules/SearchAutoComplete/styles";
@import "../components/molecules/SearchDropdown/styles";
Expand Down