-
Notifications
You must be signed in to change notification settings - Fork 64
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: add rating field #2636
Merged
Merged
feat: add rating field #2636
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
81dc5ca
feat: adjust color for actionable rating
artursantiago a400c12
feat: add disable rating styles
artursantiago fae8175
feat: create RatingField component
artursantiago 76a6a23
feat: change rating component colors
artursantiago fee26d8
feat(RatingField): use data attribute instead of svg tag
artursantiago 7ba8bf9
styles: biome fix
artursantiago a361429
fix: add styles to ui styles import list
artursantiago 92b2e8c
Merge branch 'main' into feat/add-rating-field
hellofanny 9d61124
fix: indentation from merge
hellofanny 7dd77f3
fix(Rating): adjusting size of icon button for a actionable rating
artursantiago 7b52922
feat(RatingField): add spacing between input and text
artursantiago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/components/src/molecules/RatingField/RatingField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './RatingField' | ||
export type { RatingFieldProps } from './RatingField' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/ui/src/components/molecules/RatingField/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[data-fs-rating-field] { | ||
// -------------------------------------------------------- | ||
// Design Tokens for Rating Field | ||
// -------------------------------------------------------- | ||
|
||
hellofanny marked this conversation as resolved.
Show resolved
Hide 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); | ||
hellofanny marked this conversation as resolved.
Show resolved
Hide 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); | ||
hellofanny marked this conversation as resolved.
Show resolved
Hide 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
I will suggest adding a new token:
and then on line 34, force the size:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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