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

feat: palette fill as a presentation prop; getInputStylePalette fn prop; #1092

Merged
merged 7 commits into from
Dec 9, 2024

Conversation

apattersonATX-HB
Copy link
Contributor

SC-61998 | Figma

Screen.Recording.2024-12-06.at.1.49.08.PM.mov

Initially the goal was to only have select fields show color but since the underlying <TextFieldBase that actually controls colors takes props from presentationFieldProps it was pretty easy to hook up the components starting from there. So technically our <MultiselectField also supports getInputStylePalette&inputStylePaletteand our<TextFieldssupportinputStylePalette` as well practically for free.

@@ -2,6 +2,8 @@ import { createContext, PropsWithChildren, useContext, useMemo } from "react";
import { GridStyle } from "src/components/Table";
import { Typography } from "src/Css";

export type InputStylePalette = "success" | "warning" | "caution" | "info";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mirrors our coloredChips and does leave room for more bespoke customization in the future if the need arises

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I like giving the users "logical options" and keeping the physical color palette/colors internally within the component.

}

export type PresentationContextProps = {
fieldProps?: PresentationFieldProps;
fieldProps?: Omit<PresentationFieldProps, "inputStylePalette">;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not something we want set at a context level

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, that it's not a context-level thing, but then wonder if we can find a better spot for declaring it, then PresentationFieldProps?

Hm, I guess PresentationFieldProps does seem to be "common across text fields and select fields", and it isn't used by other things that aren't getting supported in this PR... 🤔 so sgtm...

Could make your PR comment an in-source comment 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"common across text fields and select fields",
Yup! Thats why its here. Comment updated

Comment on lines 244 to 250
const standardColoredSelectArgs = {
options: coloredOptions,
// @ts-ignore
getInputStylePalette,
};

export const Colored = Template.bind({});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy pasta

Comment on lines +28 to +29
/** Changes bg and hoverBg; Takes priority over `contrast`; Useful when showing many fields w/in a table that require user attention; In no way should be used as a replacement for error/focus state */
inputStylePalette?: InputStylePalette;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this since there's been a lot of discussion around how we can show to users what changes they've made at a glance, mostly in dynamic schedules. With this we can pass something in based on a form state for example if asked

@apattersonATX-HB
Copy link
Contributor Author

🕯️🕯️🕯️ Summoning @bdow to poke holes 🕯️🕯️🕯️

@@ -20,6 +20,8 @@ export interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProp
getOptionMenuLabel?: (opt: O, isUnsetOpt?: boolean, isAddNewOption?: boolean) => string | ReactNode;
getOptionValue: (opt: O) => V;
getOptionLabel: (opt: O) => string;
/** Sets an input style based on the option(s) selected if `inputStylePalette` is not set */
getInputStylePalette?: (values: V[] | undefined) => InputStylePalette | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to support something like "the select field is green when the values are [Good, Better] but the select field is red when the values are [Bad, Worse]"?

Kinda wonder if just inputStylePalette as a regular prop would be fine, and let the caller do the "well sometimes is success and sometimes its warning" on their side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. I thought getInputStylePalette lined up with our other label getters and would cut down on extra code the caller needs to write to support something like [Good, Better] or value passes some regExp combination but its basically the same in practice so i'll remove it in favor of just relying on updating inputStylePalette values

@@ -2,6 +2,8 @@ import { createContext, PropsWithChildren, useContext, useMemo } from "react";
import { GridStyle } from "src/components/Table";
import { Typography } from "src/Css";

export type InputStylePalette = "success" | "warning" | "caution" | "info";
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I like giving the users "logical options" and keeping the physical color palette/colors internally within the component.

}

export type PresentationContextProps = {
fieldProps?: PresentationFieldProps;
fieldProps?: Omit<PresentationFieldProps, "inputStylePalette">;
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, that it's not a context-level thing, but then wonder if we can find a better spot for declaring it, then PresentationFieldProps?

Hm, I guess PresentationFieldProps does seem to be "common across text fields and select fields", and it isn't used by other things that aren't getting supported in this PR... 🤔 so sgtm...

Could make your PR comment an in-source comment 🤷

@@ -23,10 +25,12 @@ export interface PresentationFieldProps {
errorInTooltip?: true;
/** Allow the fields to grow to the width of its container. By default, fields will extend up to 550px */
fullWidth?: boolean;
/** Changes bg and hoverBg; Takes priority over `contrast`; Useful when showing many fields w/in a table that require user attention; In no way should be used as a replacement for error/focus state */
Copy link
Contributor

Choose a reason for hiding this comment

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

Great docs!

Copy link
Contributor

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

Cool! Lgtm with the getInputStylePalette => dumber inputStylePalette change.

@apattersonATX-HB apattersonATX-HB merged commit 794663c into main Dec 9, 2024
5 of 6 checks passed
@apattersonATX-HB apattersonATX-HB deleted the sc-61998/single-select-field-palette-fill branch December 9, 2024 17:04
homebound-team-bot pushed a commit that referenced this pull request Dec 9, 2024
## [2.372.0](v2.371.2...v2.372.0) (2024-12-09)

### Features

* palette fill as a presentation prop; getInputStylePalette fn prop; ([#1092](#1092)) ([794663c](794663c))
@homebound-team-bot
Copy link

🎉 This PR is included in version 2.372.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants