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

[WB-1814.2] Refactor TextField and TextArea to use semantic colors #2440

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-radios-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-form": patch
---

Migrate color instances to use semanticColor internally on TextField and TextArea
5 changes: 5 additions & 0 deletions .changeset/spicy-grapes-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-tokens": minor
---

Add `border.focus` semantic color token to use for the focus outline
6 changes: 1 addition & 5 deletions __docs__/wonder-blocks-form/text-area-variants.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field";
*/
export default {
title: "Packages / Form / TextArea / All Variants",
parameters: {
docs: {
autodocs: false,
},
},
tags: ["!autodocs"],
} as Meta;

type StoryComponentType = StoryObj<typeof TextArea>;
Expand Down
8 changes: 4 additions & 4 deletions __docs__/wonder-blocks-form/text-area.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TextArea} from "@khanacademy/wonder-blocks-form";
import packageConfig from "../../packages/wonder-blocks-form/package.json";

import ComponentInfo from "../components/component-info";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
import Button from "@khanacademy/wonder-blocks-button";
import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
import {Strut} from "@khanacademy/wonder-blocks-layout";
Expand Down Expand Up @@ -50,12 +50,12 @@ type ControlledStoryComponentType = StoryObj<typeof ControlledTextArea>;

const styles = StyleSheet.create({
customField: {
backgroundColor: color.darkBlue,
color: color.white,
backgroundColor: semanticColor.status.notice.background,
color: semanticColor.status.notice.foreground,
border: "none",
maxWidth: 250,
"::placeholder": {
color: color.white64,
color: semanticColor.text.secondary,
},
},
});
Expand Down
8 changes: 4 additions & 4 deletions __docs__/wonder-blocks-form/text-field.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {Meta, StoryObj} from "@storybook/react";

import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
import {Strut} from "@khanacademy/wonder-blocks-layout";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
import Button from "@khanacademy/wonder-blocks-button";
import {LabelLarge, Body} from "@khanacademy/wonder-blocks-typography";

Expand Down Expand Up @@ -828,12 +828,12 @@ AutoComplete.parameters = {

const styles = StyleSheet.create({
customField: {
backgroundColor: color.darkBlue,
color: color.white,
backgroundColor: semanticColor.status.notice.background,
color: semanticColor.status.notice.foreground,
border: "none",
maxWidth: 250,
"::placeholder": {
color: color.white64,
color: semanticColor.text.secondary,
},
},
button: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 {spacing} from "@khanacademy/wonder-blocks-tokens";
import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
import SearchField from "@khanacademy/wonder-blocks-search-field";
import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field";
Expand Down Expand Up @@ -123,9 +123,6 @@ export const Active: StoryComponentType = {
};

const styles = StyleSheet.create({
darkDefault: {
backgroundColor: color.darkBlue,
},
statesContainer: {
padding: spacing.medium_16,
},
Expand Down
10 changes: 5 additions & 5 deletions packages/wonder-blocks-form/src/components/field-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {StyleSheet} from "aphrodite";

import {View, addStyle, StyleType} from "@khanacademy/wonder-blocks-core";
import {Strut} from "@khanacademy/wonder-blocks-layout";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
import {LabelMedium, LabelSmall} from "@khanacademy/wonder-blocks-typography";

type Props = {
Expand Down Expand Up @@ -136,15 +136,15 @@ export default class FieldHeading extends React.Component<Props> {

const styles = StyleSheet.create({
label: {
color: color.offBlack,
color: semanticColor.text.primary,
},
description: {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
error: {
color: color.red,
color: semanticColor.status.critical.foreground,
},
required: {
color: color.red,
color: semanticColor.status.critical.foreground,
Comment on lines +139 to +148
Copy link
Member

Choose a reason for hiding this comment

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

So clean and straightforward 🤩

},
});
45 changes: 25 additions & 20 deletions packages/wonder-blocks-form/src/components/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
addStyle,
View,
} from "@khanacademy/wonder-blocks-core";
import {border, color, font, spacing} from "@khanacademy/wonder-blocks-tokens";
import {
border,
font,
semanticColor,
spacing,
} from "@khanacademy/wonder-blocks-tokens";
import {styles as typographyStyles} from "@khanacademy/wonder-blocks-typography";
import {useId} from "react";
import {useFieldValidation} from "../hooks/use-field-validation";
Expand Down Expand Up @@ -312,45 +317,45 @@ const styles = StyleSheet.create({
}px`,
},
default: {
background: color.white,
border: `1px solid ${color.offBlack50}`,
color: color.offBlack,
background: semanticColor.surface.primary,
border: `${border.width.hairline}px solid ${semanticColor.border.strong}`,
color: semanticColor.text.primary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here around if we want to have a separate token for placeholder text color! (comment from other PR: #2438 (comment))

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed with Design and they are good with this approach.

},
},
defaultFocus: {
":focus-visible": {
borderColor: color.blue,
outline: `1px solid ${color.blue}`,
borderColor: semanticColor.border.focus,
outline: `${border.width.hairline}px solid ${semanticColor.border.focus}`,
// Negative outline offset so it focus outline is not cropped off if
// an ancestor element has overflow: hidden
outlineOffset: "-2px",
outlineOffset: -2,
},
},
disabled: {
background: color.offWhite,
border: `1px solid ${color.offBlack16}`,
color: color.offBlack64,
background: semanticColor.action.disabled.secondary,
border: `${border.width.hairline}px solid ${semanticColor.border.primary}`,
color: semanticColor.text.secondary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
cursor: "not-allowed",
":focus-visible": {
outline: `2px solid ${color.offBlack32}`,
outlineOffset: "-3px",
outline: `${border.width.thin}px solid ${semanticColor.action.disabled.default}`,
outlineOffset: -3,
},
},
error: {
background: color.fadedRed8,
border: `1px solid ${color.red}`,
color: color.offBlack,
background: semanticColor.status.critical.background,
border: `${border.width.hairline}px solid ${semanticColor.status.critical.foreground}`,
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to have semanticColor.status.critical.border here and in the focus-visible state?

Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned in other PRs, the goal is to keep status as it is. I'll create a ticket to also simplify the action tokens once we have something more defined a more stable visual direction for the new experience.

color: semanticColor.text.primary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
":focus-visible": {
outlineColor: color.red,
borderColor: color.red,
outlineColor: semanticColor.status.critical.foreground,
borderColor: semanticColor.status.critical.foreground,
},
},
});
Expand Down
44 changes: 24 additions & 20 deletions packages/wonder-blocks-form/src/components/text-field.tsx
Copy link
Member

Choose a reason for hiding this comment

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

Same comments from TextArea for TextField since they have similar styles!

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as React from "react";
import {StyleSheet} from "aphrodite";

import {Id, addStyle} from "@khanacademy/wonder-blocks-core";
import {border, color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {
border,
semanticColor,
spacing,
} from "@khanacademy/wonder-blocks-tokens";
import {styles as typographyStyles} from "@khanacademy/wonder-blocks-typography";

import type {StyleType, AriaProps} from "@khanacademy/wonder-blocks-core";
Expand Down Expand Up @@ -268,45 +272,45 @@ const styles = StyleSheet.create({
margin: 0,
},
default: {
background: color.white,
border: `1px solid ${color.offBlack50}`,
color: color.offBlack,
background: semanticColor.surface.primary,
border: `${border.width.hairline}px solid ${semanticColor.border.strong}`,
color: semanticColor.text.primary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
},
defaultFocus: {
":focus-visible": {
borderColor: color.blue,
outline: `1px solid ${color.blue}`,
borderColor: semanticColor.border.focus,
outline: `${border.width.hairline}px solid ${semanticColor.border.focus}`,
// Negative outline offset so it focus outline is not cropped off if
// an ancestor element has overflow: hidden
outlineOffset: "-2px",
outlineOffset: -2,
},
},
error: {
background: color.fadedRed8,
border: `1px solid ${color.red}`,
color: color.offBlack,
background: semanticColor.status.critical.background,
border: `${border.width.hairline}px solid ${semanticColor.status.critical.foreground}`,
color: semanticColor.text.primary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
":focus-visible": {
outlineColor: color.red,
borderColor: color.red,
outlineColor: semanticColor.status.critical.foreground,
borderColor: semanticColor.status.critical.foreground,
},
},
disabled: {
background: color.offWhite,
border: `1px solid ${color.offBlack16}`,
color: color.offBlack64,
background: semanticColor.action.disabled.secondary,
border: `${border.width.hairline}px solid ${semanticColor.border.primary}`,
color: semanticColor.text.secondary,
"::placeholder": {
color: color.offBlack64,
color: semanticColor.text.secondary,
},
cursor: "not-allowed",
":focus-visible": {
outline: `2px solid ${color.offBlack32}`,
outlineOffset: "-3px",
outline: `${border.width.thin}px solid ${semanticColor.action.disabled.default}`,
outlineOffset: -3,
},
},
});
Expand Down
1 change: 1 addition & 0 deletions packages/wonder-blocks-tokens/src/tokens/semantic-color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const border = {
primary: color.fadedOffBlack16,
subtle: color.fadedOffBlack8,
strong: color.fadedOffBlack50,
focus: color.blue,
Copy link
Member

Choose a reason for hiding this comment

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

🎉

inverse: color.white,
};

Expand Down
Loading