forked from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Weaverse:main' into main
- Loading branch information
Showing
104 changed files
with
684 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,138 @@ | ||
import type { | ||
InspectorGroup, | ||
HydrogenComponentProps, | ||
HydrogenComponentSchema, | ||
} from "@weaverse/hydrogen"; | ||
import type { VariantProps } from "class-variance-authority"; | ||
import { cva } from "class-variance-authority"; | ||
import { clsx } from "clsx"; | ||
import { forwardRef } from "react"; | ||
import { Link } from "@remix-run/react"; | ||
import clsx from "clsx"; | ||
import { Link } from "~/modules"; | ||
|
||
import { missingClass } from "~/lib/utils"; | ||
export interface ButtonProps extends VariantProps<typeof variants> { | ||
as?: keyof HTMLElementTagNameMap; | ||
className?: string; | ||
text: string; | ||
link?: string; | ||
openInNewTab?: boolean; | ||
} | ||
|
||
export const Button = forwardRef( | ||
( | ||
{ | ||
as = "button", | ||
className = "", | ||
variant = "primary", | ||
width = "auto", | ||
...props | ||
}: { | ||
as?: React.ElementType; | ||
className?: string; | ||
variant?: "primary" | "secondary" | "inline" | "secondary-white"; | ||
width?: "auto" | "full"; | ||
[key: string]: any; | ||
let variants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap text-base font-medium transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50", | ||
{ | ||
variants: { | ||
variant: { | ||
primary: "btn-primary border-2 px-5 py-3", | ||
secondary: "btn-secondary border-2 px-5 py-3", | ||
link: "btn-link bg-transparent py-2 border-b-2", | ||
}, | ||
shape: { | ||
square: "", | ||
rounded: "rounded-md", | ||
pill: "rounded-full", | ||
}, | ||
weight: { | ||
medium: "font-medium", | ||
semibold: "font-semibold", | ||
bold: "font-bold", | ||
}, | ||
}, | ||
ref, | ||
) => { | ||
const Component = props?.to ? Link : as; | ||
|
||
const baseButtonClasses = | ||
"inline-block rounded font-medium text-center py-3 px-4 text-sm font-medium"; | ||
|
||
const disabledClasses = | ||
"disabled:opacity-50 disabled:cursor-not-allowed disabled:select-none disabled:hover:bg-btn disabled:hover:text-btn-content"; | ||
|
||
const variants = { | ||
primary: `${baseButtonClasses} border-2 border-btn hover:bg-inv-btn hover:text-inv-btn-content bg-btn text-btn-content`, | ||
secondary: `${baseButtonClasses} border-2 border-btn text-btnTextInverse hover:bg-btn hover:text-btn-content`, | ||
"secondary-white": `${baseButtonClasses} border-2 border-inv-btn text-btn hover:bg-inv-btn hover:text-inv-btn-content`, | ||
inline: "border-b border-bar/10 leading-none pb-1", | ||
}; | ||
|
||
const widths = { | ||
auto: "w-auto", | ||
full: "w-full", | ||
}; | ||
|
||
const styles = clsx( | ||
missingClass(className, "bg-") && variants[variant], | ||
missingClass(className, "w-") && widths[width], | ||
disabledClasses, | ||
className, | ||
); | ||
defaultVariants: { | ||
variant: "primary", | ||
shape: "rounded", | ||
weight: "medium", | ||
}, | ||
}, | ||
); | ||
|
||
interface Props extends ButtonProps, Partial<HydrogenComponentProps> {} | ||
|
||
let Button = forwardRef<HTMLElement, Props>((props, ref) => { | ||
let { | ||
// as = "button", | ||
variant, | ||
// shape = "rounded", | ||
// weight = "medium", | ||
text, | ||
link, | ||
openInNewTab, | ||
className, | ||
...rest | ||
} = props; | ||
|
||
if (link) { | ||
return ( | ||
<Component | ||
// @todo: not supported until react-router makes it into Remix. | ||
// preventScrollReset={true} | ||
className={styles} | ||
{...props} | ||
ref={ref} | ||
/> | ||
<Link | ||
ref={ref as React.ForwardedRef<HTMLAnchorElement>} | ||
{...rest} | ||
className={clsx(variants({ variant: variant, className }))} | ||
to={link || "/"} | ||
target={openInNewTab ? "_blank" : "_self"} | ||
rel="noreferrer" | ||
> | ||
{text} | ||
</Link> | ||
); | ||
} | ||
return ( | ||
<button | ||
ref={ref as React.ForwardedRef<HTMLButtonElement>} | ||
{...rest} | ||
type="button" | ||
className={clsx(variants({ variant: variant, className }))} | ||
> | ||
{text} | ||
</button> | ||
); | ||
}); | ||
|
||
export default Button; | ||
|
||
export let buttonInputs: InspectorGroup["inputs"] = [ | ||
{ | ||
type: "text", | ||
name: "text", | ||
label: "Text content", | ||
defaultValue: "Shop now", | ||
placeholder: "Shop now", | ||
}, | ||
); | ||
{ | ||
type: "url", | ||
name: "link", | ||
label: "Link to", | ||
defaultValue: "/products", | ||
placeholder: "/products", | ||
}, | ||
{ | ||
type: "switch", | ||
name: "openInNewTab", | ||
label: "Open in new tab", | ||
defaultValue: false, | ||
condition: "buttonLink.ne.nil", | ||
}, | ||
{ | ||
type: "select", | ||
name: "variant", | ||
label: "Variant", | ||
configs: { | ||
options: [ | ||
{ label: "Primary", value: "primary" }, | ||
{ label: "Secondary", value: "secondary" }, | ||
{ label: "Link", value: "link" }, | ||
], | ||
}, | ||
defaultValue: "primary", | ||
}, | ||
]; | ||
|
||
export let schema: HydrogenComponentSchema = { | ||
type: "button", | ||
title: "Button", | ||
inspector: [ | ||
{ | ||
group: "Button", | ||
inputs: buttonInputs, | ||
}, | ||
], | ||
toolbar: ["general-settings", ["duplicate", "delete"]], | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
export { Layout } from "./Layout"; | ||
export { Drawer, useDrawer } from "./Drawer"; | ||
export { Heading, Section, Text, PageHeader } from "./Text"; | ||
export { Input } from "./Input"; | ||
export { ProductGallery } from "./ProductGallery"; | ||
export { ProductCard } from "./ProductCard"; | ||
export { ProductSwimlane } from "./ProductSwimlane"; | ||
export { Skeleton } from "./Skeleton"; | ||
export { Button } from "./Button"; | ||
export { CountrySelector } from "./CountrySelector"; | ||
export { Cart } from "./Cart"; | ||
export { CartLoading } from "./CartLoading"; | ||
export { OrderCard } from "./OrderCard"; | ||
export { AccountDetails } from "./AccountDetails"; | ||
export { AccountAddressBook } from "./AccountAddressBook"; | ||
export { Modal } from "./Modal"; | ||
export { Link } from "./Link"; | ||
export { FeaturedCollections } from "./FeaturedCollections"; | ||
export { Hero } from "./Hero"; | ||
export { SortFilter } from "./SortFilter"; | ||
export { Grid } from "./Grid"; | ||
export { FeaturedProducts } from "./FeaturedProducts"; | ||
export { AddToCartButton } from "./AddToCartButton"; | ||
export * from "./Icon"; | ||
import type { HydrogenComponent } from "@weaverse/hydrogen"; | ||
|
||
import * as Heading from "./Heading"; | ||
import * as SubHeading from "./SubHeading"; | ||
import * as Description from "./Description"; | ||
import * as Button from "./Button"; | ||
|
||
export let sharedComponents: HydrogenComponent[] = [ | ||
SubHeading, | ||
Heading, | ||
Description, | ||
Button, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/components/AccountDetails.tsx → app/modules/AccountDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { forwardRef } from "react"; | ||
import { Link } from "@remix-run/react"; | ||
import clsx from "clsx"; | ||
|
||
import { missingClass } from "~/lib/utils"; | ||
|
||
export const Button = forwardRef( | ||
( | ||
{ | ||
as = "button", | ||
className = "", | ||
variant = "primary", | ||
width = "auto", | ||
...props | ||
}: { | ||
as?: React.ElementType; | ||
className?: string; | ||
variant?: "primary" | "secondary" | "inline" | "secondary-white"; | ||
width?: "auto" | "full"; | ||
[key: string]: any; | ||
}, | ||
ref, | ||
) => { | ||
const Component = props?.to ? Link : as; | ||
|
||
const baseButtonClasses = | ||
"inline-block rounded font-medium text-center py-3 px-4 text-sm font-medium"; | ||
|
||
const disabledClasses = | ||
"disabled:opacity-50 disabled:cursor-not-allowed disabled:select-none disabled:hover:bg-btn disabled:hover:text-btn-content"; | ||
|
||
const variants = { | ||
primary: `${baseButtonClasses} border-2 border-btn hover:bg-inv-btn hover:text-inv-btn-content bg-btn text-btn-content`, | ||
secondary: `${baseButtonClasses} border-2 border-btn text-btnTextInverse hover:bg-btn hover:text-btn-content`, | ||
"secondary-white": `${baseButtonClasses} border-2 border-inv-btn text-btn hover:bg-inv-btn hover:text-inv-btn-content`, | ||
inline: "border-b border-bar/10 leading-none pb-1", | ||
}; | ||
|
||
const widths = { | ||
auto: "w-auto", | ||
full: "w-full", | ||
}; | ||
|
||
const styles = clsx( | ||
missingClass(className, "bg-") && variants[variant], | ||
missingClass(className, "w-") && widths[width], | ||
disabledClasses, | ||
className, | ||
); | ||
|
||
return ( | ||
<Component | ||
// @todo: not supported until react-router makes it into Remix. | ||
// preventScrollReset={true} | ||
className={styles} | ||
{...props} | ||
ref={ref} | ||
/> | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.