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
RichSelectList: fix classic & cambio styling #335
Merged
christianvuerings
merged 1 commit into
Cambly:main
from
christianvuerings:richselectlist-fix-styling
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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,6 @@ | ||
--- | ||
"@cambly/syntax-core": minor | ||
"@syntax/storybook": minor | ||
--- | ||
|
||
RichSelectList: fix styling for cambio & classic |
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ import RichSelectSection from "./RichSelectSection"; | |
import RichSelectChip from "./RichSelectChip"; | ||
import RichSelectRadioButton from "./RichSelectRadioButton"; | ||
import { useField } from "react-aria"; | ||
import { useTheme } from "../ThemeProvider/ThemeProvider"; | ||
|
||
const NOOP = () => undefined; | ||
|
||
|
@@ -61,7 +62,7 @@ export type RichSelectListProps = RichSelectBoxProps & { | |
*/ | ||
id?: string; | ||
/** Text shown above select box */ | ||
label?: string; | ||
label: string; | ||
/** | ||
* Text showing in select box if no option has been chosen. | ||
* There should always have a placeholder unless there is a default option selected | ||
|
@@ -124,6 +125,7 @@ function RichSelectList(props: RichSelectListProps): ReactElement { | |
const inputId = id ?? reactId; | ||
const isHydrated = useIsHydrated(); | ||
const disabled = !isHydrated || disabledProp; | ||
const { themeName } = useTheme(); | ||
|
||
// passed to popover, which attached open/close methods | ||
const overlayHandlerRef = useRef<OverlayHandlerRef>({}); | ||
|
@@ -176,31 +178,31 @@ function RichSelectList(props: RichSelectListProps): ReactElement { | |
<div | ||
className={classNames(styles.selectContainer, { | ||
[styles.opacityOverlay]: disabled, | ||
[styles.selectContainerCambio]: themeName === "cambio", | ||
})} | ||
> | ||
<ReactAriaLabel | ||
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.
|
||
data-testid={[dataTestId, "label"].filter(Boolean).join("-")} | ||
className={classNames( | ||
styles.selectContainer, | ||
styles.outerTextContainer, | ||
)} | ||
{...labelProps} | ||
onClick={() => { | ||
if (disabled) return; | ||
fieldRef.current?.focus(); | ||
setInteractionModality("keyboard"); // Show the focus ring so the user knows where focus went | ||
}} | ||
> | ||
{label && ( | ||
<label className={styles.label} htmlFor={id}> | ||
<Box paddingX={1}> | ||
{label && ( | ||
<> | ||
<ReactAriaLabel | ||
data-testid={[dataTestId, "label"].filter(Boolean).join("-")} | ||
className={classNames( | ||
themeName === "cambio" && styles.labelCambio, | ||
)} | ||
{...labelProps} | ||
onClick={() => { | ||
if (disabled) return; | ||
fieldRef.current?.focus(); | ||
setInteractionModality("keyboard"); // Show the focus ring so the user knows where focus went | ||
}} | ||
> | ||
<Box paddingX={themeName === "classic" ? 1 : 3}> | ||
<Typography size={100} color="gray700"> | ||
{label} | ||
</Typography> | ||
</Box> | ||
</label> | ||
)} | ||
</ReactAriaLabel> | ||
</ReactAriaLabel> | ||
</> | ||
)} | ||
<Popover | ||
ref={overlayHandlerRef} | ||
disabled={disabled} | ||
|
@@ -235,13 +237,25 @@ function RichSelectList(props: RichSelectListProps): ReactElement { | |
> | ||
<div className={styles.selectWrapper}> | ||
<div | ||
className={classNames(styles.selectBox, styles[size], { | ||
[styles.unselected]: | ||
!errorText && selectedKeys !== "all" && !selectedKeys.size, | ||
[styles.selected]: | ||
!errorText && (selectedKeys === "all" || selectedKeys.size), | ||
[styles.selectError]: errorText, | ||
})} | ||
className={classNames( | ||
styles.selectBox, | ||
themeName === "classic" | ||
? styles.selectBoxClassic | ||
: styles.selectBoxCambio, | ||
themeName === "classic" && styles[size], | ||
{ | ||
[styles.unselected]: | ||
!errorText && | ||
selectedKeys !== "all" && | ||
!selectedKeys.size, | ||
[styles.selected]: | ||
!errorText && | ||
(selectedKeys === "all" || selectedKeys.size), | ||
[themeName === "classic" | ||
? styles.selectError | ||
: styles.selectErrorCambio]: errorText, | ||
}, | ||
)} | ||
> | ||
{selectedTextValue} | ||
</div> | ||
|
@@ -264,15 +278,15 @@ function RichSelectList(props: RichSelectListProps): ReactElement { | |
</TapArea> | ||
</Popover> | ||
{(helperText || errorText) && ( | ||
<div className={styles.outerTextContainer}> | ||
<Box paddingX={themeName === "classic" ? 1 : 0}> | ||
<Typography | ||
size={100} | ||
color={errorText ? "destructive-primary" : "gray700"} | ||
{...(errorText ? errorMessageProps : descriptionProps)} | ||
> | ||
{errorText ? errorText : helperText} | ||
</Typography> | ||
</div> | ||
</Box> | ||
)} | ||
</div> | ||
</ReactAriaProvider> | ||
|
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.
@jliotta
label
should still be required but it can be an empty string. When it is an empty string, the label won't render