Skip to content

Commit

Permalink
adding new color property in Text and Link component (#2619)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Wooding <[email protected]>
  • Loading branch information
tejasnikam and joshwooding authored May 8, 2024
1 parent d972d20 commit 2cd9de7
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 27 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
className,
children,
variant = "primary",
color = "primary",
target = "_self",
...rest
},
Expand All @@ -47,6 +48,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
ref={ref}
target={target}
variant={variant}
color={color}
{...rest}
>
{children}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/text/Text.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.saltText {
--text-color: currentColor;
}

/* Main css class. Style for body text */
.saltText {
color: var(--saltText-color, var(--text-color));
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ export type TextProps<T extends ElementType> = PolymorphicComponentPropWithRef<
| "code";
/**
* Change text color palette
* @deprecated Use `color` instead
*/
variant?: "primary" | "secondary";
/*
* The color of the text. Defaults to "primary".
*/
color?: "inherit" | "primary" | "secondary";
}
>;

Expand All @@ -59,7 +64,8 @@ export const Text: TextComponent = forwardRef(
maxRows,
style,
styleAs,
variant = "primary",
variant,
color: colorProp,
...restProps
}: TextProps<T>,
ref?: PolymorphicRef<T>
Expand All @@ -71,19 +77,21 @@ export const Text: TextComponent = forwardRef(
window: targetWindow,
});

const Component = as || "div";
const Component = as ?? "div";

const textStyles = { "--text-max-rows": maxRows, ...style };

const color = variant ?? colorProp ?? "primary";

return (
<Component
className={clsx(
withBaseName(),
{
[withBaseName("disabled")]: disabled,
[withBaseName("lineClamp")]: maxRows,
[withBaseName(styleAs || "")]: styleAs,
[withBaseName(variant)]: variant,
[withBaseName(styleAs as string)]: styleAs,
[withBaseName(color)]: color !== "inherit",
},
className
)}
Expand Down
12 changes: 6 additions & 6 deletions packages/core/stories/link/link.qa.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const AllVariantsGrid: StoryFn<QAContainerProps> = (props) => (
<strong>Strong</strong> and <small>small</small> truncation example
</Link>
</div>
<Link href="https://www.google.com" variant="secondary">
<Link href="https://www.google.com" color="secondary">
Secondary Link
</Link>
<Link href="https://www.google.com" variant="secondary" target="_blank">
<Link href="https://www.google.com" color="secondary" target="_blank">
Secondary Link target blank
</Link>
<div style={{ width: 150 }}>
<Link href="https://www.google.com" maxRows={1} variant="secondary">
<Link href="https://www.google.com" maxRows={1} color="secondary">
<strong>Strong</strong> and <small>small</small> truncation example
</Link>
</div>
Expand All @@ -54,14 +54,14 @@ export const NoStyleInjectionGrid: StoryFn<QAContainerNoStyleInjectionProps> = (
<strong>Strong</strong> and <small>small</small> truncation example
</Link>
</div>
<Link href="https://www.google.com" variant="secondary">
<Link href="https://www.google.com" color="secondary">
Secondary Link
</Link>
<Link href="https://www.google.com" variant="secondary" target="_blank">
<Link href="https://www.google.com" color="secondary" target="_blank">
Secondary Link target blank
</Link>
<div style={{ width: 150 }}>
<Link href="https://www.google.com" maxRows={1} variant="secondary">
<Link href="https://www.google.com" maxRows={1} color="secondary">
<strong>Strong</strong> and <small>small</small> truncation example
</Link>
</div>
Expand Down
10 changes: 9 additions & 1 deletion packages/core/stories/link/link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ export const Primary: StoryFn<typeof Link> = () => {

export const Secondary: StoryFn<typeof Link> = () => {
return (
<Link variant="secondary" href="https://www.google.com">
<Link color="secondary" href="https://www.google.com">
Link to URL
</Link>
);
};

export const InheritColor: StoryFn<typeof Link> = () => {
return (
<Link color="inherit" href="https://www.google.com">
Link to URL
</Link>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/stories/text/text.qa.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export const AllVariantsGrid: StoryFn<QAContainerProps> = (props) => (
<Text disabled>
Primary disabled <strong>strong</strong> and <small>small</small> text
</Text>
<Text variant="secondary">
<Text color="secondary">
Secondary <strong>strong</strong> and <small>small</small> text
</Text>
<Text variant="secondary" disabled>
<Text color="secondary" disabled>
Secondary disabled <strong>strong</strong> and <small>small</small> text
</Text>
<Display1>
Expand Down
8 changes: 6 additions & 2 deletions packages/core/stories/text/text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ export const Primary: StoryFn<typeof Text> = () => {
};

export const Secondary: StoryFn<typeof Text> = () => {
return <Text variant="secondary">This is a secondary text example</Text>;
return <Text color="secondary">This is a secondary text example</Text>;
};

export const InheritColor: StoryFn<typeof Text> = () => {
return <Text color="inherit">This is a secondary text example</Text>;
};

export const Disabled: StoryFn<typeof Text> = () => {
return (
<div>
<Text disabled>This is a disabled primary text example</Text>
<Text variant="secondary" disabled>
<Text color="secondary" disabled>
This is a disabled secondary text example
</Text>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/lab/src/contact-details/ContactPrimaryInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useContactDetailsContext } from "./internal";
const withBaseName = makePrefixer("saltContactPrimaryInfo");

export interface ContactPrimaryInfoProps
extends HTMLAttributes<HTMLDivElement> {
extends Omit<HTMLAttributes<HTMLDivElement>, "color"> {
text: string;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lab/src/contact-details/ContactSecondaryInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ValueComponentProps } from "./types";
const withBaseName = makePrefixer("saltContactSecondaryInfo");

export interface ContactSecondaryInfoProps
extends HTMLAttributes<HTMLDivElement> {
extends Omit<HTMLAttributes<HTMLDivElement>, "color"> {
icon?: ComponentType<IconProps>;
text: string;
ValueComponent?: ComponentType<ValueComponentProps>;
Expand Down
2 changes: 1 addition & 1 deletion packages/lab/src/contact-details/ContactTertiaryInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useContactDetailsContext } from "./internal";
const withBaseName = makePrefixer("saltContactTertiaryInfo");

export interface ContactTertiaryInfoProps
extends HTMLAttributes<HTMLDivElement> {
extends Omit<HTMLAttributes<HTMLDivElement>, "color"> {
icon?: ComponentType<IconProps>;
text: string;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/lab/src/contact-details/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HTMLAttributes } from "react";

export interface ValueComponentProps extends HTMLAttributes<HTMLSpanElement> {
export interface ValueComponentProps
extends Omit<HTMLAttributes<HTMLSpanElement>, "color"> {
value?: string;
}
6 changes: 3 additions & 3 deletions packages/lab/src/stepped-tracker/StepLabel/StepLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { forwardRef, ComponentPropsWithoutRef, ReactNode } from "react";
import { forwardRef, ReactNode } from "react";
import { clsx } from "clsx";
import { makePrefixer, Label } from "@salt-ds/core";
import { makePrefixer, Label, TextProps } from "@salt-ds/core";
import { useComponentCssInjection } from "@salt-ds/styles";
import { useWindow } from "@salt-ds/window";

import stepLabelCss from "./StepLabel.css";

const withBaseName = makePrefixer("saltStepLabel");

export interface StepLabelProps extends ComponentPropsWithoutRef<"label"> {
export interface StepLabelProps extends TextProps<"label"> {
/**
* The content of Step Label
*/
Expand Down
20 changes: 16 additions & 4 deletions site/docs/components/link/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ When linking to third party content, we recommended setting `rel=”noopener”`

</LivePreview>

<LivePreview componentName="link" exampleName="Variant">
<LivePreview componentName="link" exampleName="Color">

## Variant
## Color

To help create a visual hierarchy using a link, use the `variant` prop.
To help create a visual hierarchy using a link, use the `color` prop.

The default variant is `primary`.
The default color is `primary`.

</LivePreview>

Expand All @@ -54,4 +54,16 @@ Links change color after a user clicks on them. This tells the user which links

</LivePreview>

<LivePreview componentName="link" exampleName="Variant" displayName="Variant - Deprecated">

## Variant

**Note:** This prop is deprecated. Use the `color` prop instead.

To help create a visual hierarchy using a link, use the `variant` prop.

The default variant is `primary`.

</LivePreview>

</LivePreviewControls>
14 changes: 13 additions & 1 deletion site/docs/components/text/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,22 @@ Using the `styleAs` prop, you can maintain the correct HTML hierarchy and the ap

</LivePreview>

<LivePreview componentName="text" exampleName="Variant">
<LivePreview componentName="text" exampleName="Color">

## Color

Use the `color` prop to adjust the foreground color of any nested text. Use the `primary` color most of the time, the `secondary` color for supporting text or to create visual hierarchy, and `inherit` to inherit text color from the parent element.

Read our [guidance on how to use text color](/salt/foundations/typography#color).

</LivePreview>

<LivePreview componentName="text" exampleName="Variant" displayName="Variant - Deprecated">

## Variant

**Note:** This prop is deprecated. Use the `color` prop instead.

Use the `variant` prop to adjust the foreground color of any nested text. Use the `primary` variant most often, and the `secondary` variant for supporting text or creating a visual hierarchy.

Read our [guidance on how to use text color](/salt/foundations/typography#color).
Expand Down
17 changes: 17 additions & 0 deletions site/src/examples/link/Color.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ReactElement } from "react";
import { Link, StackLayout } from "@salt-ds/core";
import styles from "./index.module.css";

export const Color = (): ReactElement => (
<StackLayout>
<Link href="#" color="primary" className={styles.linkExample}>
Primary Link color
</Link>
<Link href="#" color="secondary" className={styles.linkExample}>
Secondary Link color
</Link>
<Link href="#" color="inherit" className={styles.linkExample}>
Inherit Link color
</Link>
</StackLayout>
);
1 change: 1 addition & 0 deletions site/src/examples/link/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./Default";
export * from "./OpenInANewTab";
export * from "./Variant";
export * from "./Color";
export * from "./Visited";
10 changes: 10 additions & 0 deletions site/src/examples/text/Color.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ReactElement } from "react";
import { Text, StackLayout } from "@salt-ds/core";

export const Color = (): ReactElement => (
<StackLayout>
<Text color="primary">This is primary color of Text</Text>
<Text color="secondary">This is secondary color of Text</Text>
<Text color="inherit">This is inherited color of Text</Text>
</StackLayout>
);
1 change: 1 addition & 0 deletions site/src/examples/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./Styles";
export * from "./Styling";
export * from "./Truncation";
export * from "./Variant";
export * from "./Color";

0 comments on commit 2cd9de7

Please sign in to comment.