-
Notifications
You must be signed in to change notification settings - Fork 10
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
SearchField: Add validation props and refine states #2363
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
db91d02
SearchField: Add error prop and update icon styling
beaesguerra e6a0a31
SearchField: Add variants story and address styling issues by relying…
beaesguerra 5be918d
SearchField: Don't render clear icon button if the field is disabled
beaesguerra 9a012f2
Add instantValidation, validate, onValidate props to SearchField
beaesguerra 9981f8e
add tests
beaesguerra 96337dc
fix styling so hover + focus state doesn't remove the focus outline
beaesguerra 133be86
Disable chromatic snapshots
beaesguerra 173aaf5
update docs
beaesguerra 519c6a7
add changeset
beaesguerra f7ca531
add test for hiding clear button when field is disabled
beaesguerra 38d94fc
update changeset
beaesguerra ce89fc7
add test
beaesguerra 5f9f586
remove icon styling changes to revert to original styling. there were…
beaesguerra 7898c96
Fix up magnifying icon styling
beaesguerra e0569b1
Update validation story
beaesguerra 9151f56
address PR comments: clean up styling
beaesguerra d2e3190
update clear icon button: bold icon, smaller, spacing
beaesguerra b286e3a
fix lint
beaesguerra d2a4cd5
Use small size for dismiss button so it has a bigger hit area. Use th…
beaesguerra 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-search-field": minor | ||
--- | ||
|
||
# SearchField | ||
|
||
- Adds `error`, `instantValidation`, `validate`, and `onValidate` props to be consistent with form components. | ||
- Refine icon styling and use semantic color tokens | ||
- Hide the clear button if the SearchField is disabled |
167 changes: 167 additions & 0 deletions
167
__docs__/wonder-blocks-search-field/search-field-variants.stories.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,167 @@ | ||
import * as React from "react"; | ||
import {StyleSheet} from "aphrodite"; | ||
import type {Meta, StoryObj} from "@storybook/react"; | ||
|
||
import {View} from "@khanacademy/wonder-blocks-core"; | ||
import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; | ||
import {LabelLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography"; | ||
import SearchField from "@khanacademy/wonder-blocks-search-field"; | ||
|
||
/** | ||
* The following stories are used to generate the pseudo states for the | ||
* SearchField component. This is only used for visual testing in Chromatic. | ||
*/ | ||
export default { | ||
title: "Packages / SearchField / All Variants", | ||
parameters: { | ||
docs: { | ||
autodocs: false, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
type StoryComponentType = StoryObj<typeof SearchField>; | ||
|
||
const longText = | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."; | ||
const longTextWithNoWordBreak = | ||
"Loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua"; | ||
|
||
const states = [ | ||
{ | ||
label: "Default", | ||
props: {}, | ||
}, | ||
{ | ||
label: "Disabled", | ||
props: {disabled: true}, | ||
}, | ||
{ | ||
label: "Error", | ||
props: {error: true}, | ||
}, | ||
]; | ||
const States = (props: { | ||
light: boolean; | ||
label: string; | ||
value?: string; | ||
placeholder?: string; | ||
}) => { | ||
return ( | ||
<View | ||
style={[props.light && styles.darkDefault, styles.statesContainer]} | ||
> | ||
<LabelLarge style={props.light && {color: color.white}}> | ||
{props.label} | ||
</LabelLarge> | ||
<View style={[styles.scenarios]}> | ||
{states.map((scenario) => { | ||
return ( | ||
<View style={styles.scenario} key={scenario.label}> | ||
<LabelMedium | ||
style={props.light && {color: color.white}} | ||
> | ||
{scenario.label} | ||
</LabelMedium> | ||
<SearchField | ||
value="" | ||
onChange={() => {}} | ||
{...props} | ||
{...scenario.props} | ||
/> | ||
</View> | ||
); | ||
})} | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const AllVariants = () => ( | ||
<View> | ||
{[false, true].map((light) => { | ||
return ( | ||
<React.Fragment key={`light-${light}`}> | ||
<States light={light} label="Default" /> | ||
<States light={light} label="With Value" value="Text" /> | ||
<States | ||
light={light} | ||
label="With Value (long)" | ||
value={longText} | ||
/> | ||
<States | ||
light={light} | ||
label="With Value (long, no word breaks)" | ||
value={longTextWithNoWordBreak} | ||
/> | ||
<States | ||
light={light} | ||
label="With Placeholder" | ||
placeholder="Placeholder text" | ||
/> | ||
<States | ||
light={light} | ||
label="With Placeholder (long)" | ||
placeholder={longText} | ||
/> | ||
<States | ||
light={light} | ||
label="With Placeholder (long, no word breaks)" | ||
placeholder={longTextWithNoWordBreak} | ||
/> | ||
</React.Fragment> | ||
); | ||
})} | ||
</View> | ||
); | ||
|
||
export const Default: StoryComponentType = { | ||
render: AllVariants, | ||
}; | ||
|
||
/** | ||
* There are currently only hover styles on the clear button. | ||
*/ | ||
export const Hover: StoryComponentType = { | ||
render: AllVariants, | ||
parameters: {pseudo: {hover: true}}, | ||
}; | ||
|
||
export const Focus: StoryComponentType = { | ||
render: AllVariants, | ||
parameters: {pseudo: {focusVisible: true}}, | ||
}; | ||
|
||
export const HoverFocus: StoryComponentType = { | ||
name: "Hover + Focus", | ||
render: AllVariants, | ||
parameters: {pseudo: {hover: true, focusVisible: true}}, | ||
}; | ||
|
||
/** | ||
* There are currently no active styles. | ||
*/ | ||
export const Active: StoryComponentType = { | ||
render: AllVariants, | ||
parameters: {pseudo: {active: true}}, | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
darkDefault: { | ||
backgroundColor: color.darkBlue, | ||
}, | ||
statesContainer: { | ||
padding: spacing.medium_16, | ||
}, | ||
scenarios: { | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
gap: spacing.xxxLarge_64, | ||
flexWrap: "wrap", | ||
}, | ||
scenario: { | ||
gap: spacing.small_12, | ||
overflow: "hidden", | ||
}, | ||
}); |
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.
super-nit:
View
providesflex
by default.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.
Removed! (🦸 super-nit 😄)