Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/five-impalas-tan.md
@@ -0,0 +1,6 @@
---
"@cambly/syntax-core": minor
"@syntax/storybook": minor
---

RichSelectList: fix styling for cambio & classic
72 changes: 43 additions & 29 deletions packages/syntax-core/src/RichSelect/RichSelectList.tsx
Expand Up @@ -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;

Expand Down Expand Up @@ -61,7 +62,7 @@ export type RichSelectListProps = RichSelectBoxProps & {
*/
id?: string;
/** Text shown above select box */
label?: string;
label: string;
Copy link
Contributor Author

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

/**
* Text showing in select box if no option has been chosen.
* There should always have a placeholder unless there is a default option selected
Expand Down Expand Up @@ -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>({});
Expand Down Expand Up @@ -176,31 +178,31 @@ function RichSelectList(props: RichSelectListProps): ReactElement {
<div
className={classNames(styles.selectContainer, {
[styles.opacityOverlay]: disabled,
[styles.selectContainerCambio]: themeName === "cambio",
})}
>
<ReactAriaLabel
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReactAriaLabel renders a label and we rendered a label inside of it. Fix that

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}
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions packages/syntax-core/src/SelectList/SelectList.module.css
Expand Up @@ -52,6 +52,7 @@
.selectBoxCambio {
border: 1px solid var(--color-cambio-gray-370);
border-radius: 8px;
box-sizing: border-box;
font-size: 14px;
height: 48px;
padding: 12px 36px 0 12px;
Expand Down