Skip to content

Commit

Permalink
chore: update examples/stackflow-spa
Browse files Browse the repository at this point in the history
  • Loading branch information
malangcat committed Jan 3, 2025
1 parent 4c53b8c commit f4c9284
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 163 deletions.
3 changes: 1 addition & 2 deletions examples/stackflow-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"dependencies": {
"@daangn/react-monochrome-icon": "^0.0.13",
"@radix-ui/react-slot": "^1.1.0",
"@seed-design/react": "0.0.0",
"@seed-design/react-popover": "0.0.0-alpha-20241030023710",
"@seed-design/react-radio-group": "0.0.0-alpha-20241030023710",
"@seed-design/react-switch": "0.0.0-alpha-20241030023710",
"@seed-design/react-tabs": "0.0.0-alpha-20241209060641",
"@seed-design/react-text-field": "0.0.0-alpha-20241030023710",
"@seed-design/recipe": "0.0.0-alpha-20241212122822",
Expand Down
54 changes: 27 additions & 27 deletions examples/stackflow-spa/src/design-system/ui/action-button.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
"use client";

import "@seed-design/stylesheet/progressCircle.css";
// TODO: we have to ensure load order between actionButton.css and progressCircle.css. should we bundle them together?
import "@seed-design/stylesheet/actionButton.css";

import { ActionButton as SeedActionButton } from "@seed-design/react";
import * as React from "react";
import clsx from "clsx";
import { Slot } from "@radix-ui/react-slot";
import { actionButton, type ActionButtonVariantProps } from "@seed-design/recipe/actionButton";

export interface ActionButtonProps extends ActionButtonVariantProps {
export interface ActionButtonProps extends SeedActionButton.RootProps {
prefixIcon?: React.ReactNode;

suffixIcon?: React.ReactNode;

/**
* @default false
*/
asChild?: boolean;
}

interface ReactActionButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
ActionButtonProps {}

/**
* @see https://v3.seed-design.io/docs/react/components/action-button
*/
export const ActionButton = React.forwardRef<HTMLButtonElement, ReactActionButtonProps>(
export const ActionButton = React.forwardRef<
React.ElementRef<typeof SeedActionButton.Root>,
ActionButtonProps
>(
(
{
className,
variant = "brandSolid",
size = "medium",
children,
loading = false,
layout = "withText",
prefixIcon,
suffixIcon,
layout = "withText",
asChild = false,
children,
...otherProps
},
ref,
) => {
const Comp = asChild ? Slot : "button";
const classNames = actionButton({ variant, layout, size });
return (
<Comp ref={ref} className={clsx(classNames.root, className)} {...otherProps}>
{prefixIcon && <Slot className={classNames.prefixIcon}>{prefixIcon}</Slot>}
<SeedActionButton.Root ref={ref} loading={loading} layout={layout} {...otherProps}>
{layout === "withText" ? (
<span className={classNames.label}>{children}</span>
<>
{prefixIcon && <SeedActionButton.PrefixIcon svg={prefixIcon} />}
<SeedActionButton.Label>{children}</SeedActionButton.Label>
{suffixIcon && <SeedActionButton.SuffixIcon svg={suffixIcon} />}
</>
) : (
<Slot className={classNames.icon}>{children}</Slot>
<SeedActionButton.Icon svg={children} />
)}
{suffixIcon && <Slot className={classNames.suffixIcon}>{suffixIcon}</Slot>}
</Comp>
{loading ? <SeedActionButton.ProgressCircle /> : null}
</SeedActionButton.Root>
);
},
);
ActionButton.displayName = "ActionButton";

/**
* This file is generated snippet from the Seed Design.
* You can extend the functionality from this snippet if needed.
*/
61 changes: 18 additions & 43 deletions examples/stackflow-spa/src/design-system/ui/action-chip.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,39 @@
import { Slot } from "@radix-ui/react-slot";
import {
actionChip,
type ActionChipVariantProps,
} from "@seed-design/recipe/actionChip";
import clsx from "clsx";
"use client";

import { ActionChip as SeedActionChip } from "@seed-design/react";
import * as React from "react";

import "@seed-design/stylesheet/actionChip.css";

export interface ActionChipProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
ActionChipVariantProps {
export interface ActionChipProps extends SeedActionChip.RootProps {
prefixIcon?: React.ReactNode;

suffixIcon?: React.ReactNode;

count?: number;

asChild?: boolean;
}

export const ActionChip = React.forwardRef<HTMLButtonElement, ActionChipProps>(
(
{
className,
size = "medium",
layout = "withText",
children,
prefixIcon,
suffixIcon,
count,
asChild = false,
...otherProps
},
ref,
) => {
const Comp = asChild ? Slot : "button";
const classNames = actionChip({ size, layout });
({ className, children, prefixIcon, suffixIcon, count, ...otherProps }, ref) => {
return (
<Comp
ref={ref}
className={clsx(classNames.root, className)}
{...otherProps}
>
{layout === "withText" ? (
<SeedActionChip.Root ref={ref} {...otherProps}>
{otherProps.layout === "withText" ? (
<>
{prefixIcon && (
<Slot className={classNames.prefixIcon}>{prefixIcon}</Slot>
)}
<span className={classNames.label}>{children}</span>
{count && <span className={classNames.count}>{count}</span>}
{suffixIcon && (
<Slot className={classNames.suffixIcon}>{suffixIcon}</Slot>
)}
{prefixIcon && <SeedActionChip.PrefixIcon svg={prefixIcon} />}
<SeedActionChip.Label>{children}</SeedActionChip.Label>
{count && <SeedActionChip.Count>{count}</SeedActionChip.Count>}
{suffixIcon && <SeedActionChip.SuffixIcon svg={suffixIcon} />}
</>
) : (
<Slot className={classNames.icon}>{children}</Slot>
<SeedActionChip.Icon svg={children} />
)}
</Comp>
</SeedActionChip.Root>
);
},
);
ActionChip.displayName = "ActionChip";

/**
* This file is generated snippet from the Seed Design.
* You can extend the functionality from this snippet if needed.
*/
85 changes: 19 additions & 66 deletions examples/stackflow-spa/src/design-system/ui/control-chip.tsx
Original file line number Diff line number Diff line change
@@ -1,85 +1,33 @@
import { Slot } from "@radix-ui/react-slot";
import {
controlChip,
type ControlChipVariantProps,
} from "@seed-design/recipe/controlChip";
import clsx from "clsx";
"use client";

import { ControlChip as SeedControlChip } from "@seed-design/react";
import * as React from "react";

import "@seed-design/stylesheet/controlChip.css";
import {
type UseCheckboxProps,
useCheckbox,
} from "@seed-design/react-checkbox";
import { visuallyHidden } from "../util/visuallyHidden";

export interface ControlChipToggleProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
UseCheckboxProps,
ControlChipVariantProps {
export interface ControlChipToggleProps extends SeedControlChip.RootProps {
prefixIcon?: React.ReactNode;

suffixIcon?: React.ReactNode;

count?: number;
}

const ControlChipToggle = React.forwardRef<
HTMLInputElement,
ControlChipToggleProps
>(
(
{
className,
size = "medium",
layout = "withText",
children,
prefixIcon,
suffixIcon,
count,
...otherProps
},
ref,
) => {
const classNames = controlChip({ size, layout });
const { rootProps, hiddenInputProps, stateProps, restProps } =
useCheckbox(otherProps);

export const ControlChipToggle = React.forwardRef<HTMLLabelElement, ControlChipToggleProps>(
({ className, children, prefixIcon, suffixIcon, count, ...otherProps }, ref) => {
return (
<label {...rootProps} className={clsx(classNames.root, className)}>
{layout === "withText" ? (
<SeedControlChip.Root ref={ref} {...otherProps}>
{otherProps.layout === "withText" ? (
<>
{prefixIcon && (
<Slot {...stateProps} className={classNames.prefixIcon}>
{prefixIcon}
</Slot>
)}
<span {...stateProps} className={classNames.label}>
{children}
</span>
{count && (
<span {...stateProps} className={classNames.count}>
{count}
</span>
)}
{suffixIcon && (
<Slot {...stateProps} className={classNames.suffixIcon}>
{suffixIcon}
</Slot>
)}
{prefixIcon && <SeedControlChip.PrefixIcon svg={prefixIcon} />}
<SeedControlChip.Label>{children}</SeedControlChip.Label>
{count && <SeedControlChip.Count>{count}</SeedControlChip.Count>}
{suffixIcon && <SeedControlChip.SuffixIcon svg={suffixIcon} />}
</>
) : (
<Slot {...stateProps} className={classNames.icon}>
{children}
</Slot>
<SeedControlChip.Icon svg={children} />
)}
<input
ref={ref}
{...hiddenInputProps}
{...restProps}
style={visuallyHidden}
/>
</label>
</SeedControlChip.Root>
);
},
);
Expand All @@ -95,3 +43,8 @@ export const ControlChip = Object.assign(
Toggle: ControlChipToggle,
},
);

/**
* This file is generated snippet from the Seed Design.
* You can extend the functionality from this snippet if needed.
*/
38 changes: 15 additions & 23 deletions examples/stackflow-spa/src/design-system/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { type UseSwitchProps, useSwitch } from "@seed-design/react-switch";
import { type SwitchVariantProps, switchStyle } from "@seed-design/recipe/switch";
import clsx from "clsx";
import * as React from "react";
"use client";

import type { Assign } from "../util/types";
import { visuallyHidden } from "../util/visuallyHidden";
import * as React from "react";
import { Switch as SeedSwitch } from "@seed-design/react";

import "@seed-design/stylesheet/switch.css";

export interface SwitchProps extends SwitchVariantProps {}

interface ReactSwitchProps
extends Assign<React.HTMLAttributes<HTMLInputElement>, UseSwitchProps>,
SwitchProps {}

export const Switch = React.forwardRef<HTMLInputElement, ReactSwitchProps>(
({ className, size = "medium", ...otherProps }, ref) => {
const { restProps, controlProps, hiddenInputProps, rootProps, thumbProps } =
useSwitch(otherProps);
const classNames = switchStyle({ size });
export interface SwitchProps extends SeedSwitch.RootProps {
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
rootRef?: React.Ref<HTMLLabelElement>;
}

export const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
({ inputProps, rootRef, ...otherProps }, ref) => {
return (
<label className={clsx(classNames.root, className)} {...rootProps}>
<div {...controlProps} className={classNames.control}>
<div {...thumbProps} className={classNames.thumb} />
</div>
<input ref={ref} {...hiddenInputProps} {...restProps} style={visuallyHidden} />
</label>
<SeedSwitch.Root ref={rootRef} {...otherProps}>
<SeedSwitch.Control>
<SeedSwitch.Thumb />
</SeedSwitch.Control>
<SeedSwitch.HiddenInput ref={ref} {...inputProps} />
</SeedSwitch.Root>
);
},
);
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8007,9 +8007,8 @@ __metadata:
"@daangn/react-monochrome-icon": "npm:^0.0.13"
"@radix-ui/react-slot": "npm:^1.1.0"
"@seed-design/cli": "npm:0.0.0-alpha-20241204134404"
"@seed-design/react": "npm:0.0.0"
"@seed-design/react-popover": "npm:0.0.0-alpha-20241030023710"
"@seed-design/react-radio-group": "npm:0.0.0-alpha-20241030023710"
"@seed-design/react-switch": "npm:0.0.0-alpha-20241030023710"
"@seed-design/react-tabs": "npm:0.0.0-alpha-20241209060641"
"@seed-design/react-text-field": "npm:0.0.0-alpha-20241030023710"
"@seed-design/recipe": "npm:0.0.0-alpha-20241212122822"
Expand Down

0 comments on commit f4c9284

Please sign in to comment.