Skip to content

Commit

Permalink
Use SaltProviderNext
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z committed Jul 8, 2024
1 parent 40a8418 commit fdaff9a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { withResponsiveWrapper } from "docs/decorators/withResponsiveWrapper";
import { WithTextSpacingWrapper } from "docs/decorators/withTextSpacingWrapper";
import { withScaffold } from "docs/decorators/withScaffold";
import { withDateMock } from "docs/decorators/withDateMock";
import { SaltProvider, UNSTABLE_SaltProviderNext } from "@salt-ds/core";
import { SaltProvider, SaltProviderNext } from "@salt-ds/core";
import { DocsContainer } from "@storybook/addon-docs";
import { initialize, mswLoader } from "msw-storybook-addon";

Expand Down Expand Up @@ -151,7 +151,7 @@ export const parameters: Parameters = {
const ChosenProvider =
/* @ts-ignore Waiting for https://github.com/storybookjs/storybook/issues/12982 */
context.store.globals.globals?.themeNext === "enable"
? UNSTABLE_SaltProviderNext
? SaltProviderNext
: SaltProvider;
return (
<DocsContainer context={context} {...rest}>
Expand Down
10 changes: 3 additions & 7 deletions docs/components/QAContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
makePrefixer,
Mode,
SaltProvider,
UNSTABLE_SaltProviderNext,
SaltProviderNext,
useTheme,
} from "@salt-ds/core";
import { clsx } from "clsx";
Expand Down Expand Up @@ -60,9 +60,7 @@ const DensityBlock = ({
mode: Mode;
}) => {
const { themeNext } = useTheme();
const ChosenSaltProvider = themeNext
? UNSTABLE_SaltProviderNext
: SaltProvider;
const ChosenSaltProvider = themeNext ? SaltProviderNext : SaltProvider;

return (
<BackgroundBlock background={mode === "light" ? "white" : undefined}>
Expand Down Expand Up @@ -99,9 +97,7 @@ export const QAContainer = ({
} as CSSProperties;

const { themeNext } = useTheme();
const ChosenSaltProvider = themeNext
? UNSTABLE_SaltProviderNext
: SaltProvider;
const ChosenSaltProvider = themeNext ? SaltProviderNext : SaltProvider;

return (
<div
Expand Down
5 changes: 2 additions & 3 deletions docs/decorators/withTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Panel,
SaltProvider,
useTheme,
UNSTABLE_SaltProviderNext,
SaltProviderNext,
} from "@salt-ds/core";
import { useEffect } from "react";

Expand Down Expand Up @@ -76,8 +76,7 @@ export const withTheme: Decorator = (StoryFn, context) => {
actionFont,
} = context.globals;

const Provider =
themeNext === "enable" ? UNSTABLE_SaltProviderNext : SaltProvider;
const Provider = themeNext === "enable" ? SaltProviderNext : SaltProvider;

if (mode === "side-by-side" || mode === "stacked") {
const isStacked = mode === "stacked";
Expand Down
8 changes: 2 additions & 6 deletions packages/ag-grid-theme/src/examples/HDCompact.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
SaltProvider,
UNSTABLE_SaltProviderNext,
useTheme,
} from "@salt-ds/core";
import { SaltProvider, SaltProviderNext, useTheme } from "@salt-ds/core";
import { AgGridReact, AgGridReactProps } from "ag-grid-react";
import dataGridExampleColumns from "../dependencies/dataGridExampleColumns";
import dataGridExampleData from "../dependencies/dataGridExampleData";
Expand All @@ -27,7 +23,7 @@ const HDCompact = (props: AgGridReactProps) => {
density: "high",
});

const Provider = themeNext ? UNSTABLE_SaltProviderNext : SaltProvider;
const Provider = themeNext ? SaltProviderNext : SaltProvider;

return (
<Provider density="high">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useAriaAnnouncer,
useDensity,
useTheme,
UNSTABLE_SaltProviderNext,
SaltProviderNext,
} from "@salt-ds/core";
import { mount } from "cypress/react18";
import { WindowProvider } from "@salt-ds/window";
Expand Down Expand Up @@ -322,9 +322,9 @@ describe("Given a SaltProviderNext", () => {
describe("with no props set", () => {
it("should apply default theme attributes to the html element", () => {
mount(
<UNSTABLE_SaltProviderNext>
<SaltProviderNext>
<TestComponent />
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
);

cy.get("div.salt-provider").should("have.length", 0);
Expand All @@ -342,9 +342,9 @@ describe("Given a SaltProviderNext", () => {
});
it("should read correct default values from provider and add an AriaAnnouncer", () => {
mount(
<UNSTABLE_SaltProviderNext>
<SaltProviderNext>
<TestComponent />
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
);
cy.get("#test-1")
.should("exist")
Expand Down Expand Up @@ -403,7 +403,7 @@ describe("Given a SaltProviderNext", () => {
describe("when nested", () => {
it("should inherit values not passed as props", () => {
mount(
<UNSTABLE_SaltProviderNext
<SaltProviderNext
density="high"
mode="dark"
corner="rounded"
Expand All @@ -412,10 +412,10 @@ describe("Given a SaltProviderNext", () => {
actionFont="Amplitude"
>
<TestComponent />
<UNSTABLE_SaltProviderNext density="medium">
<SaltProviderNext density="medium">
<TestComponent id="test-2" />
</UNSTABLE_SaltProviderNext>
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
</SaltProviderNext>
);

cy.get("html.salt-theme-next").should("have.length", 1);
Expand Down Expand Up @@ -451,7 +451,7 @@ describe("Given a SaltProviderNext", () => {
});
it("should take different values set as props", () => {
mount(
<UNSTABLE_SaltProviderNext
<SaltProviderNext
density="high"
mode="dark"
corner="rounded"
Expand All @@ -460,16 +460,16 @@ describe("Given a SaltProviderNext", () => {
actionFont="Amplitude"
>
<TestComponent />
<UNSTABLE_SaltProviderNext
<SaltProviderNext
density="medium"
corner="sharp"
accent="blue"
headingFont="Open Sans"
actionFont="Open Sans"
>
<TestComponent id="test-2" />
</UNSTABLE_SaltProviderNext>
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
</SaltProviderNext>
);

cy.get("html.salt-theme-next").should("have.length", 1);
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/__tests__/__e2e__/utils/useFloatingUI.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mount } from "cypress/react18";
import {
useFloatingComponent,
SaltProvider,
UNSTABLE_SaltProviderNext,
SaltProviderNext,
useFloatingUI,
} from "@salt-ds/core";

Expand Down Expand Up @@ -45,11 +45,11 @@ describe("Use useFloatingComponent", () => {
cy.get("html.salt-theme").should("have.length", 1);
cy.get("div.salt-provider.salt-theme").should("have.length", 1);
});
it("should render a nested UNSTABLE_SaltProviderNext when used within another", () => {
it("should render a nested SaltProviderNext when used within another", () => {
mount(
<UNSTABLE_SaltProviderNext>
<SaltProviderNext>
<TestComponent focusManager={false} />
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
);

cy.get("html.salt-theme.salt-theme-next").should("have.length", 1);
Expand All @@ -70,11 +70,11 @@ describe("Use useFloatingComponent", () => {
cy.get("html.salt-theme").should("have.length", 1);
cy.get("div.salt-provider.salt-theme").should("have.length", 1);
});
it("should render a nested UNSTABLE_SaltProviderNext when used within another", () => {
it("should render a nested SaltProviderNext when used within another", () => {
mount(
<UNSTABLE_SaltProviderNext>
<SaltProviderNext>
<TestComponent focusManager={true} />
</UNSTABLE_SaltProviderNext>
</SaltProviderNext>
);

cy.get("html.salt-theme.salt-theme-next").should("have.length", 1);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/salt-provider/SaltProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
export const DEFAULT_DENSITY = "medium";

const DEFAULT_THEME_NAME = "salt-theme";
const UNSTABLE_ADDITIONAL_THEME_NAME = "salt-theme-next";
const DEFAULT_THEME_NAME_NEXT = "salt-theme-next";

const DEFAULT_MODE = "light";
const DEFAULT_CORNER: Corner = "sharp";
Expand Down Expand Up @@ -91,8 +91,8 @@ const getThemeNames = (
): ThemeName => {
if (themeNext) {
return themeName === DEFAULT_THEME_NAME
? clsx(DEFAULT_THEME_NAME, UNSTABLE_ADDITIONAL_THEME_NAME)
: clsx(DEFAULT_THEME_NAME, UNSTABLE_ADDITIONAL_THEME_NAME, themeName);
? clsx(DEFAULT_THEME_NAME, DEFAULT_THEME_NAME_NEXT)
: clsx(DEFAULT_THEME_NAME, DEFAULT_THEME_NAME_NEXT, themeName);
} else {
return themeName === DEFAULT_THEME_NAME
? themeName
Expand Down Expand Up @@ -246,7 +246,7 @@ function InternalSaltProvider({
accent: accentProp,
actionFont: actionFontProp,
}: Omit<
SaltProviderProps & ThemeNextProps & UNSTABLE_SaltProviderNextProps,
SaltProviderProps & ThemeNextProps & SaltProviderNextProps,
"enableStyleInjection"
>) {
const inheritedDensity = useContext(DensityContext);
Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/utils/useFloatingUI/useFloatingUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import {
useContext,
useMemo,
} from "react";
import {
SaltProvider,
UNSTABLE_SaltProviderNext,
useTheme,
} from "../../salt-provider";
import { SaltProvider, SaltProviderNext, useTheme } from "../../salt-provider";

export interface FloatingComponentProps
extends ComponentPropsWithoutRef<"div"> {
Expand Down Expand Up @@ -75,9 +71,7 @@ const DefaultFloatingComponent = forwardRef<

const { themeNext } = useTheme();

const ChosenSaltProvider = themeNext
? UNSTABLE_SaltProviderNext
: SaltProvider;
const ChosenSaltProvider = themeNext ? SaltProviderNext : SaltProvider;

if (focusManagerProps && open) {
return (
Expand Down
12 changes: 6 additions & 6 deletions packages/core/stories/salt-provider/salt-provider-next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ density). Additional props will be made available to switch between different
look.

To use the new Salt Provider, you need to swap any existing `SaltProvider` to
use the new `UNSTABLE_SaltProviderNext`, and also import a new theme CSS.
use the new `SaltProviderNext`, and also import a new theme CSS.

```js static
// Swap out existing SaltProvider
import { UNSTABLE_SaltProviderNext } from "@salt-ds/core";
import { SaltProviderNext } from "@salt-ds/core";
```

```js static
Expand Down Expand Up @@ -93,7 +93,7 @@ either blue or teal color palette, such as CTA button, checkbox, radio button,
etc.

```tsx
<UNSTABLE_SaltProviderNext accent="teal">
<SaltProviderNext accent="teal">
```

Under the hood, a new `data-accent` attribute is added alongside other style option
Expand Down Expand Up @@ -125,7 +125,7 @@ The `corner` prop can be used to toggle between `"sharp"` (default) and
`"rounded"`.

```tsx
<UNSTABLE_SaltProviderNext corner="rounded">
<SaltProviderNext corner="rounded">
```

### Token Structure
Expand Down Expand Up @@ -200,7 +200,7 @@ A new `headingFont` prop is added to switch display and heading font family
between Open Sans and Amplitude.

```
<UNSTABLE_SaltProviderNext headingFont="Amplitude">
<SaltProviderNext headingFont="Amplitude">
```

When Amplitude is used, default heading font weight is set to medium (instead
Expand Down Expand Up @@ -231,7 +231,7 @@ A new `actionFont` prop is added to switch action font family between Open Sans
and Amplitude, which impacts Button, Toggle Button and Segmented Button Group.

```
<UNSTABLE_SaltProviderNext actionFont="Amplitude">
<SaltProviderNext actionFont="Amplitude">
```

Like `headingFont` option above, you'll need the same font declaration for Amplitude
Expand Down

0 comments on commit fdaff9a

Please sign in to comment.