Skip to content

Commit

Permalink
Update guides (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Gaudin authored Jul 4, 2024
2 parents 43e07d6 + 7f029a9 commit 344ad0a
Show file tree
Hide file tree
Showing 61 changed files with 910 additions and 306 deletions.
5 changes: 4 additions & 1 deletion apps/docs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
"@next/next/no-html-link-for-pages": "off"
},
"globals": {
"BreakpointTable": true,
"Card": true,
"Callout": true,
"Collapsible": true,
"Table": true,
"TokenTable": true,
"MotionPreview": true,
"Footnote": true,
"TypographyTable": true,
"TypographyVariantTable": true,
"Tabs": true,
"TableSection": true,
"SimpleTable": true,
"Switcher": true,
"IconSpecTable": true,
"Overview": true,
"PreviewComponent": true,
"MigrateGuide": true,
"PackageInstallation": true,
"PropTable": true,
"CodeOnlyExample": true,
"Example": true
},
"overrides": [
Expand Down
20 changes: 20 additions & 0 deletions apps/docs/app/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
--hd-color-accent-text: var(--hd-accent-700);
--hd-color-accent-border: var(--hd-accent-700);
--hd-color-accent-surface: var(--hd-accent-100);
--hd-color-information-surface: #D9EFFF;
--hd-color-information-icon: #2E70A8;
--hd-color-message-surface: var(--hd-accent-100);
--hd-color-message-icon: var(--hd-accent-700);
--hd-color-warning-surface: #FFF8D6;
--hd-color-warning-icon: #E57723;
--hd-color-error-surface: #FDE6E5;
--hd-color-error-icon: #CB2E31;
--hd-color-success-surface: var(--hd-primary-100);
--hd-color-success-icon: var(--hd-primary-600);
--hd-color-surface-neutral-gradient: linear-gradient(0deg, #151515 0%, #353434 100%);
--hd-color-surface-neutral-gradient-hover: linear-gradient(0deg, #353434 0%, #151515 100%);
--hd-focus-ring: 0 0 0 0.125rem var(--hd-neutral-20), 0 0 0 0.25rem var(--hd-neutral-900);
Expand Down Expand Up @@ -123,6 +133,16 @@
--hd-color-accent-text: var(--hd-accent-300);
--hd-color-accent-border: var(--hd-accent-700);
--hd-color-accent-surface: var(--hd-accent-900);
--hd-color-information-surface: #D9EFFF;
--hd-color-information-icon: #2E70A8;
--hd-color-message-surface: var(--hd-accent-100);
--hd-color-message-icon: var(--hd-accent-700);
--hd-color-warning-surface: #FFF8D6;
--hd-color-warning-icon: #E57723;
--hd-color-error-surface: #FDE6E5;
--hd-color-error-icon: #CB2E31;
--hd-color-success-surface: var(--hd-primary-100);
--hd-color-success-icon: var(--hd-primary-600);
--hd-color-surface-neutral-gradient: linear-gradient(0deg, #F4F3EE 0%, var(--hd-neutral-0) 100%);
--hd-color-surface-neutral-gradient-hover: linear-gradient(0deg, var(--hd-neutral-0) 0%, #F4F3EE 100%);
--hd-focus-ring: 0 0 0 0.125rem var(--hd-neutral-800), 0 0 0 0.25rem var(--hd-neutral-20);
Expand Down
24 changes: 24 additions & 0 deletions apps/docs/app/ui/components/breakpointTable/BreakpointTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";

import SimpleTable from "../simpleTable/SimpleTable";
import { Breakpoints } from "@hopper-ui/components";

export default function BreakpointTable() {
const breakpoints = Object.entries(Breakpoints).map(([key, value]) => {
return {
name: key,
value: `min-width: ${value}px`
};
});

return (
<SimpleTable
aria-label="Breakpoints"
headers={["Name", "Media query"]}
data={[
{ name: "base", value: "min-width: 0px" },
...breakpoints
]}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
"use client";

import { useState, memo, type ReactNode, useCallback } from "react";
import { useState, memo, type ReactNode, useCallback, useContext, useEffect } from "react";
import Card from "@/components/card/Card.tsx";
import ThemeSwitch from "@/components/themeSwitch/ThemeSwitch.tsx";
import type { ColorScheme } from "@/context/theme/ThemeProvider.tsx";
import { StyledSystemProvider } from "@hopper-ui/styled-system";
import { ThemeContext, type ColorScheme } from "@/context/theme/ThemeProvider.tsx";

import "./componentPreviewWrapper.css";
import { HopperProvider } from "@hopper-ui/components";

interface ComponentPreviewWrapperProps {
preview?: ReactNode;
toggleButton?: ReactNode;
height?: string;
minHeight?: string;
}

const ComponentPreviewWrapper = memo(({ preview, toggleButton, height = "13rem" }: ComponentPreviewWrapperProps) => {
const [colorScheme, setColorScheme] = useState<"light" | "dark">("light");
const ComponentPreviewWrapper = memo(({ preview, toggleButton, minHeight = "13rem" }: ComponentPreviewWrapperProps) => {
const { colorMode = "light" } = useContext(ThemeContext);
const [localColorMode, setLocalColorMode] = useState(colorMode);

useEffect(() => {
// keep the local color mode in sync with the global color mode when the global changes
setLocalColorMode(colorMode);
}, [colorMode]);

const toggleTheme = useCallback(() => {
const theme: ColorScheme = colorScheme === "dark"
const theme: ColorScheme = localColorMode === "dark"
? "light"
: "dark";

setColorScheme(theme);
}, [colorScheme]);
setLocalColorMode(theme);
}, [localColorMode]);

return (
<div
className="hd-component-preview-wrapper"
data-schema={colorScheme}
style={{ height: height }}
data-schema={localColorMode}
style={{ minHeight: minHeight }}
>
<div className="hd-component-preview-wrapper__actions">
{toggleButton}
<ThemeSwitch className="hd-component-preview-wrapper__action"
onChange={toggleTheme}
colorMode={colorScheme}
colorMode={localColorMode}
/>
</div>
<Card className="hd-component-preview-wrapper__card" size="sm">
<StyledSystemProvider colorScheme={colorScheme}>
<Card className="hd-component-preview-wrapper__card" size="sm" style={{ minHeight: minHeight }}>
<HopperProvider colorScheme={localColorMode}>
{preview}
</StyledSystemProvider>
</HopperProvider>
</Card>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
height: 100%;
}

[data-schema="light"] {
.hd-component-preview-wrapper[data-schema="light"] {
.hd-component-preview-wrapper__card {
--background: var(--hd-white);
--color: var(--hd-neutral-900);
--dot-background: var(--hd-neutral-50);
}

Expand All @@ -26,9 +27,10 @@
}
}

[data-schema="dark"] {
.hd-component-preview-wrapper[data-schema="dark"] {
.hd-component-preview-wrapper__card {
--background: var(--hd-neutral-900);
--color: var(--hd-neutral-0);
--dot-background: var(--hd-neutral-800);
}

Expand Down
13 changes: 8 additions & 5 deletions apps/docs/app/ui/components/overview/overview.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
grid-template-columns: repeat(auto-fill, minmax(18.125rem, 1fr));
}

.hd-component-overview-item__link {
display: grid;
grid-template-rows: 9rem 1fr;
justify-items: stretch;
width: 100%;
height: 100%;
}

.hd-component-overview-item {
overflow: hidden;
flex-direction: column;
transition: box-shadow cubic-bezier(0.4, 0, 0.2, 1) 0.4s;
}

Expand All @@ -24,12 +31,8 @@
align-items: center;
justify-content: center;
width: 100%;
aspect-ratio: 16 / 9;
}

.hd-component-overview-item__link {
width: 100%;
}

.hd-component-overview-item__title {
font-size: 1.125rem;
Expand Down
49 changes: 49 additions & 0 deletions apps/docs/app/ui/components/simpleTable/SimpleTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import clsx from "clsx";

interface SimpleTableProps {
"aria-label"?: string;
headers: string[];
data: object[];
lastColumnAlignment?: "left" | "right";
}

export default async function SimpleTable({ "aria-label": ariaLabel, headers, data, lastColumnAlignment }: SimpleTableProps) {
return (
<table aria-label={ariaLabel} className="hd-table">
<thead>
<tr>
{headers.map((header, index) => {
const classNames = clsx("hd-table__column", { "hd-table__colum--right": index === headers.length - 1 && lastColumnAlignment === "right" });

return (
// eslint-disable-next-line react/no-array-index-key
<th key={index} className={classNames}>
{header}
</th>
);
})}
</tr>
</thead>
<tbody>
{data.map((row, rowIndex) => {
return (
// eslint-disable-next-line react/no-array-index-key
<tr key={rowIndex} className="hd-table__row">
{
Object.entries(row).map(([key, value], index) => {
const classNames = clsx("hd-table__cell", { "hd-table__cell--right": index === headers.length - 1 && lastColumnAlignment === "right" });

return (
<td key={key} className={classNames}>
{value}
</td>
);
})
}
</tr>
);
})}
</tbody>
</table>
);
}
32 changes: 29 additions & 3 deletions apps/docs/components/callout/Callout.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import type { Meta, StoryObj } from "@storybook/react";

import Callout from "./Callout.tsx";
import { Callout } from "./Callout.tsx";

const meta = {
title: "components/Callout",
component: Callout
component: Callout,
args: {
children: "Content of the callout"
}
} satisfies Meta<typeof Callout>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {}
};

export const Warning: Story = {
args: {
children: "Content of the callout"
variant: "warning"
}
};

export const Success: Story = {
args: {
variant: "success"
}
};

export const Error: Story = {
args: {
variant: "error"
}
};

export const Message: Story = {
args: {
variant: "message"
}
};

43 changes: 38 additions & 5 deletions apps/docs/components/callout/Callout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
import type { ReactNode } from "react";
"use client";

import { createContext, type ForwardedRef, forwardRef, type ReactNode } from "react";
import { type ContextValue, useContextProps } from "react-aria-components";
import clsx from "clsx";

import { Icon, WarningIcon, CheckIcon, ErrorIcon, InfoIcon, MessageIcon } from "@/components/icon";

import "./callout.css";

export interface CalloutProps {
children: ReactNode;
className?: string;
variant?: "information" | "success" | "warning" | "error" | "message";
}

const Callout = ({ children }: CalloutProps) => {
function Callout(props: CalloutProps, ref: ForwardedRef<HTMLDivElement>) {
[props, ref] = useContextProps(props, ref, CalloutContext);
const { children, className, variant = "information", ...other } = props;

const iconMap = {
information: InfoIcon,
success: CheckIcon,
warning: WarningIcon,
error: ErrorIcon,
message: MessageIcon
};

const IconSrc = iconMap[variant] || InfoIcon;

return (
<div className="hd-callout">
<div {...other}
className={clsx("hd-callout", className, {
[`hd-callout--${variant}`]: variant
})}
ref={ref}
role="alert"
>
<Icon className="hd-callout__icon" src={IconSrc} />
{children}
</div>
);
};
}

export const CalloutContext = createContext<ContextValue<Partial<CalloutProps>, HTMLDivElement>>({});

const _Callout = forwardRef<HTMLDivElement, CalloutProps>(Callout);
_Callout.displayName = "Callout";

export default Callout;
export { _Callout as Callout };
Loading

0 comments on commit 344ad0a

Please sign in to comment.