Skip to content

Commit

Permalink
Merge branch 'main' into contact-details-add-typography
Browse files Browse the repository at this point in the history
  • Loading branch information
alycrys authored Jun 23, 2022
2 parents 65cca91 + 68cfe8c commit 3b9e56c
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-suits-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@jpmorganchase/uitk-core": patch
---

Add CSS variables to API for button icon
5 changes: 5 additions & 0 deletions .changeset/thin-items-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@jpmorganchase/uitk-lab": patch
---

refactor: remove duplicated `Status` declaration
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Test"
on: [push, workflow_dispatch]
on: [push, workflow_dispatch, pull_request]

jobs:
lint:
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const withBaseName = makePrefixer("uitkButton");
export const ButtonVariantValues = ["primary", "secondary", "cta"] as const;
export type ButtonVariant = typeof ButtonVariantValues[number];

interface Props<T extends ElementType> {
export interface ButtonBaseProps<T extends ElementType> {
/**
* By default, root element of Button will be a `button` HTMLElement. This behaviour
* can be changed by passing a value to elementType. This can be a string
Expand Down Expand Up @@ -47,8 +47,8 @@ interface Props<T extends ElementType> {
variant?: ButtonVariant;
}

export type ButtonProps<T extends ElementType = "button"> = Props<T> &
Omit<ComponentPropsWithoutRef<T>, keyof Props<T>>;
export type ButtonProps<T extends ElementType = "button"> = ButtonBaseProps<T> &
Omit<ComponentPropsWithoutRef<T>, keyof ButtonBaseProps<T>>;

type PolymorphicButton = <T extends ElementType = "button">(
p: ButtonProps<T> & { ref?: polymorphicRef<T> }
Expand Down
2 changes: 2 additions & 0 deletions packages/icons/src/icon/Icon.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
letter-spacing: var(--uitkIcon-letter-spacing, normal);
speak: none;
display: inline-block;
margin: var(--uitkIcon-margin, 0);
padding: var(--uitkIcon-padding, 0);
position: relative;
box-sizing: border-box;
/* Reset 1.3 line height Toolkit sets */
Expand Down
3 changes: 3 additions & 0 deletions packages/lab/src/badge/Badge.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* Default variables applied to the root element */
.uitkBadge {
/* Colors */
--badge-content-text-color: var(--uitkBadge-content-text-color, var(--uitk-accent-foreground));
Expand All @@ -19,6 +20,7 @@
--badge-sequence-gap: var(--uitk-size-unit);
}

/* Style applied to the root element */
.uitkBadge {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand All @@ -36,6 +38,7 @@
margin-left: var(--badge-sequence-gap);
}

/* Style applied to the badge in the corner of the node */
.uitkBadge-badge {
color: var(--badge-content-text-color);
box-sizing: border-box;
Expand Down
10 changes: 4 additions & 6 deletions packages/lab/src/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
const withBaseName = makePrefixer("uitkBadge");

export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(function Badge(
props,
ref
) {
const {
{
badgeContent = 0,
max = 1000,
className,
children = <MessageIcon size={12} />,
...rest
} = props;

},
ref
) {
const badgeId = useId();
const childId = useId(
isValidElement<HTMLAttributes<HTMLElement>>(children)
Expand Down
26 changes: 10 additions & 16 deletions packages/lab/src/content-status/ContentStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@ export type ContentStatusStatus =
| "warning"
| "info";

export const Status = {
LOADING: "loading" as ContentStatusStatus,
ERROR: "error" as ContentStatusStatus,
SUCCESS: "success" as ContentStatusStatus,
WARNING: "warning" as ContentStatusStatus,
INFO: "info" as ContentStatusStatus,
export const STATUS_TO_ICONS: {
[key in Exclude<ContentStatusStatus, "loading">]: string;
} = {
error: "error",
success: "tick",
warning: "warning",
info: "info",
};

export const STATUS_TO_ICONS = {
[Status.ERROR]: "error",
[Status.SUCCESS]: "tick",
[Status.WARNING]: "warning",
[Status.INFO]: "info",
};

export type Status = keyof typeof Status;
export type Status = ContentStatusStatus;

export interface ContentStatusProps extends HTMLAttributes<HTMLDivElement> {
CircularProgressProps?: Partial<CircularProgressProps>;
Expand All @@ -70,7 +64,7 @@ export const ContentStatus = forwardRef(function ContentStatus(
disableAnnouncer,
message,
onActionClick,
status = Status.INFO,
status = "info",
title,
unit = "%",
value,
Expand All @@ -97,7 +91,7 @@ export const ContentStatus = forwardRef(function ContentStatus(
toBeAnnounced.push(message);
}
// Loading is announced by the spinner
if (status !== Status.LOADING) {
if (status !== "loading") {
toBeAnnounced.push(status);
}
if (toBeAnnounced.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const contentByType = new Map<
]);

export function renderStatusIndicator({
status = Status.INFO,
status = "info",
disableAnnouncer,
unit,
value,
Expand All @@ -72,7 +72,7 @@ export function renderStatusIndicator({
id,
}: Partial<ContentStatusProps>): ReactElement {
const { icon: Icon, className } = contentByType.get(status)!;
if (status === Status.LOADING) {
if (status === "loading") {
return value !== undefined
? getDeterminateLoadingComponent({
unit,
Expand Down
19 changes: 19 additions & 0 deletions packages/lab/stories/Badge.stories.newapp-badge.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.uitk-light.uitk-newapp .uitkBadge-success {
--uitkBadge-content-icon-color: var(--uitk-color-green-10);
--uitkBadge-content-text-color: var(--uitk-color-black);
}

.uitk-light.uitk-newapp .uitkBadge-error {
--uitkBadge-content-icon-color: var(--uitk-color-red-10);
--uitkBadge-content-text-color: var(--uitk-color-black);
}

.uitk-dark.uitk-newapp .uitkBadge-success {
--uitkBadge-content-icon-color: var(--uitk-status-success-foreground);
--uitkBadge-content-text-color: var(--uitk-color-white);
}

.uitk-dark.uitk-newapp .uitkBadge-error {
--uitkBadge-content-icon-color: var(--uitk-status-error-foreground);
--uitkBadge-content-text-color: var(--uitk-color-white);
}
174 changes: 174 additions & 0 deletions packages/lab/stories/badge.doc.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { Meta, Story, Canvas, ArgsTable } from "@storybook/addon-docs";
import { ComponentAnatomy } from "docs/components/ComponentAnatomy";
import { ToolkitProvider } from "@jpmorganchase/uitk-core";
import { Badge } from "@jpmorganchase/uitk-lab";
import {
MessageIcon,
ClockIcon,
SettingsSolidIcon,
UserBadgeIcon,
} from "@jpmorganchase/uitk-icons";
import { withFlexGap } from "docs/decorators/withFlexGap";
import {
CSSClassTable,
CSSVariableTable,
CharacteristicUsage,
} from "css-variable-docgen-components";
import { CustomStyling } from "./badge.stories";

<Meta
title="Documentation/Lab/Badge"
component={Badge}
parameters={{
viewMode: "docs",
}}
/>

# Badge

A Badge is a numeric annotation that indicates the number of outstanding items that need to be addressed. It appears on the top-right of an element, usually an icon. The badge can accommodate values of up to four digits in length.

## Icon Badge

The default element is `MessageIcon`

<Canvas>
<Story name="Default Badge">
<Badge badgeContent={1} max={1000}>
<MessageIcon />
</Badge>
</Story>
</Canvas>

## Words Badge

<Canvas>
<Story name="Words Badge">
<Badge badgeContent={10} max={1000}>
Words Badge
</Badge>
</Story>
</Canvas>

## Badge with text

`badgeContent` can accept both number and string

<Canvas>
<Story name="Text Badge">
<Badge badgeContent="Text">Text Badge</Badge>
</Story>
</Canvas>

## Badge with maximum number

Specify the maximum number to be displayed with `max`. If `badgeContent` exceeds `max`, suffix `+` will be appended.

<Canvas>
<Story name="Badge with max number">
<Badge badgeContent={150} max={99}>
<UserBadgeIcon />
</Badge>
</Story>
</Canvas>

# API

```
import { Badge } from "@jpmorganchase/uitk-lab";
```

## Props

<ArgsTable of={Badge} />

## HTML Anatomy of Badge component

<Canvas>
<ComponentAnatomy showLegend>
<Badge badgeContent={1} max={100}>
<ClockIcon />
</Badge>
</ComponentAnatomy>
<ComponentAnatomy showLegend>
<Badge badgeContent="Text">Text Badge</Badge>
</ComponentAnatomy>
<ComponentAnatomy showLegend>
<Badge badgeContent={150} max={99}>
<UserBadgeIcon />
</Badge>
</ComponentAnatomy>
</Canvas>

## CSS Class

<CSSClassTable of={Badge} />

## Characteristics Used

<CharacteristicUsage of={Badge} />

## --uitkBadge CSS Custom Property API

The default colors of the badge are provided by the theme variables. See Theme documentation for detailed usage guidance.

The CSS custom properties below are consumed by Badge, but not defined by Badge. They can be defined via a container or
a custom class name to override badge styling. They will always take precedence over default styles, whether from theme variable
or declared locally. Again, see Theme documentation for guidance on when to use variables from the Custom Property API.

<CSSVariableTable of={Badge} />

## Customising Badge styles

<Canvas>
<Story name="Custom Badge Styling" decorators={[withFlexGap]}>
<>
<ToolkitProvider theme={["light", "newapp"]}>
<Badge badgeContent={1} max={100} className="uitkBadge-success">
<MessageIcon />
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["light", "newapp"]}>
<Badge badgeContent="Text" className="uitkBadge-error">
Text Badge
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["dark", "newapp"]}>
<Badge badgeContent={1} max={100} className="uitkBadge-success">
<MessageIcon />
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["dark", "newapp"]}>
<Badge badgeContent="Text" className="uitkBadge-error">
Text Badge
</Badge>
</ToolkitProvider>
</>
</Story>
</Canvas>

The CSS is as simple as below:

```css
/* from the file Badge.stories.newapp-badge.css */

.uitk-light.uitk-newapp .uitkBadge-success {
--uitkBadge-content-icon-color: var(--uitk-color-green-10);
--uitkBadge-content-text-color: var(--uitk-color-black);
}

.uitk-light.uitk-newapp .uitkBadge-error {
--uitkBadge-content-icon-color: var(--uitk-color-red-10);
--uitkBadge-content-text-color: var(--uitk-color-black);
}

.uitk-dark.uitk-newapp .uitkBadge-success {
--uitkBadge-content-icon-color: var(--uitk-status-success-foreground);
--uitkBadge-content-text-color: var(--uitk-color-white);
}

.uitk-dark.uitk-newapp .uitkBadge-error {
--uitkBadge-content-icon-color: var(--uitk-status-error-foreground);
--uitkBadge-content-text-color: var(--uitk-color-white);
}
```
30 changes: 30 additions & 0 deletions packages/lab/stories/badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { ToolkitProvider } from "@jpmorganchase/uitk-core";
import { Badge } from "@jpmorganchase/uitk-lab";

import {
ClockIcon,
SettingsSolidIcon,
UserBadgeIcon,
MessageIcon,
} from "@jpmorganchase/uitk-icons";

import "./badge.stories.css";
import "./Badge.stories.newapp-badge.css";

import { ComponentMeta, ComponentStory } from "@storybook/react";

Expand Down Expand Up @@ -62,3 +67,28 @@ WordsBadge.args = {
badgeContent: 1,
children: "Lorem Ipsum",
};

export const CustomStyling: ComponentStory<typeof Badge> = () => (
<>
<ToolkitProvider theme={["light", "newapp"]}>
<Badge badgeContent={1} max={100} className="uitkBadge-success">
<MessageIcon />
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["light", "newapp"]}>
<Badge badgeContent="Text" className="uitkBadge-error">
Text Badge
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["dark", "newapp"]}>
<Badge badgeContent={1} max={100} className="uitkBadge-success">
<MessageIcon />
</Badge>
</ToolkitProvider>
<ToolkitProvider theme={["dark", "newapp"]}>
<Badge badgeContent="Text" className="uitkBadge-error">
Text Badge
</Badge>
</ToolkitProvider>
</>
);

0 comments on commit 3b9e56c

Please sign in to comment.