-
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
WB-1779: Add startIcon prop to Combobox #2364
base: main
Are you sure you want to change the base?
Changes from 3 commits
5a182f0
0b0c21d
1c65f4d
a2a3291
eeb6c3e
76790a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-dropdown": minor | ||
--- | ||
|
||
Add `startIcon` prop to Combobox |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import IconButton from "@khanacademy/wonder-blocks-icon-button"; | |
import {border, color, spacing} from "@khanacademy/wonder-blocks-tokens"; | ||
|
||
import {DetailCell} from "@khanacademy/wonder-blocks-cell"; | ||
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; | ||
import {useListbox} from "../hooks/use-listbox"; | ||
import {useMultipleSelection} from "../hooks/use-multiple-selection"; | ||
import { | ||
|
@@ -132,6 +133,13 @@ type Props = { | |
*/ | ||
// TODO(WB-1740): Add support to `inline` and `both` values. | ||
autoComplete?: "none" | "list" | undefined; | ||
|
||
/** | ||
* An optional decorative icon to display at the start of the combobox. | ||
*/ | ||
startIcon?: React.ReactElement< | ||
React.ComponentProps<typeof PhosphorIcon> | ||
> | null; | ||
}; | ||
|
||
/** | ||
|
@@ -158,6 +166,7 @@ export default function Combobox({ | |
opened, | ||
placeholder, | ||
selectionType = "single", | ||
startIcon, | ||
testId, | ||
value = "", | ||
}: Props) { | ||
|
@@ -477,6 +486,24 @@ export default function Combobox({ | |
return [labelFromSelected]; | ||
}, [children, labelFromSelected, selected]); | ||
|
||
/** | ||
* Renders the start icon if provided. | ||
*/ | ||
const maybeRenderStartIcon = () => { | ||
if (!startIcon) { | ||
return null; | ||
} | ||
|
||
const startIconElement = React.cloneElement(startIcon, { | ||
...startIcon.props, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: (no changes necessary) What do you think about providing a default size and color if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love it! |
||
// Override the disable state of the icon to match the combobox | ||
// state. | ||
color: disabled ? color.offBlack32 : startIcon.props.color, | ||
} as Partial<React.ReactElement<React.ComponentProps<typeof PhosphorIcon>>>); | ||
|
||
return <View style={styles.iconWrapper}>{startIconElement}</View>; | ||
}; | ||
|
||
const pillIdPrefix = id ? `${id}-pill-` : ids.get("pill"); | ||
|
||
const currentActiveDescendant = !openState | ||
|
@@ -534,6 +561,8 @@ export default function Combobox({ | |
removeSelectedLabel={labels.removeSelected} | ||
/> | ||
)} | ||
{maybeRenderStartIcon()} | ||
|
||
<TextField | ||
id={ids.get("input")} | ||
testId={testId} | ||
|
@@ -682,6 +711,12 @@ const styles = StyleSheet.create({ | |
border: `1px solid ${color.red}`, | ||
color: color.offBlack, | ||
}, | ||
/** | ||
* Start icon styles | ||
*/ | ||
iconDisabled: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think this isn't used! |
||
color: color.offBlack32, | ||
}, | ||
/** | ||
* Combobox input styles | ||
*/ | ||
|
@@ -739,4 +774,11 @@ const styles = StyleSheet.create({ | |
// This is calculated based on the padding + width of the arrow button. | ||
right: spacing.xLarge_32 + spacing.xSmall_8, | ||
}, | ||
iconWrapper: { | ||
padding: spacing.xxxSmall_4, | ||
// View has a default minWidth of 0, which causes the label text | ||
// to encroach on the icon when it needs to truncate. We can fix | ||
// this by setting the minWidth to auto. | ||
minWidth: "auto", | ||
}, | ||
}); |
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.
Let's consolidate on the magnifying icon styling! In SearchField, I updated the following to match the design more closely:
size=small
color=semanticColor.icon.primary
@phosphor-icons/core/bold/magnifying-glass-bold.svg
Let me know though if we prefer to stick with the existing styles, I can update SearchField to change it back to how it was! (I was assuming Figma was the source of truth for styling, but that may not be the case!)
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.
Sounds great! I hope GH includes the 💯 emoji in their msg reactions at some point.
To clarify after our last convo, size would be
small
right? (medium was for the dismiss icon).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.
The magnifying glass PhosphorIcon size will be small!
The clear/dismiss IconButton size is also small and the x icon is the regular icon weight!
They're both
"small"
, but the PhosphorIcon renders a 16x16 icon and IconButton renders a 24x24 icon!