diff --git a/app/components/Button.tsx b/app/components/Button.tsx index 04ec81ed..c70a5d55 100644 --- a/app/components/Button.tsx +++ b/app/components/Button.tsx @@ -1,7 +1,7 @@ import type { - InspectorGroup, HydrogenComponentProps, HydrogenComponentSchema, + InspectorGroup, } from "@weaverse/hydrogen"; import type { VariantProps } from "class-variance-authority"; import { cva } from "class-variance-authority"; @@ -16,7 +16,7 @@ export interface ButtonProps extends VariantProps { text: string; link?: string; openInNewTab?: boolean; - buttonStyle: "inherit" | "custom"; + buttonStyle?: "inherit" | "custom"; backgroundColor?: string; textColor?: string; borderColor?: string; @@ -120,7 +120,7 @@ let Button = forwardRef((props, ref) => { export default Button; -export let buttonInputs: InspectorGroup["inputs"] = [ +export let buttonContentInputs: InspectorGroup["inputs"] = [ { type: "text", name: "text", @@ -155,9 +155,11 @@ export let buttonInputs: InspectorGroup["inputs"] = [ }, defaultValue: "primary", }, +]; +export let buttonStylesInputs: InspectorGroup["inputs"] = [ { type: "heading", - label: "Styles", + label: "Button styles", }, { type: "select", @@ -170,6 +172,8 @@ export let buttonInputs: InspectorGroup["inputs"] = [ ], }, defaultValue: "inherit", + helpText: + "Select 'Inherit' to use the default button styles from global theme settings, or 'Custom' to customize the button styles.", }, { type: "color", @@ -215,6 +219,11 @@ export let buttonInputs: InspectorGroup["inputs"] = [ }, ]; +export let buttonInputs: InspectorGroup["inputs"] = [ + ...buttonContentInputs, + ...buttonStylesInputs, +]; + export let schema: HydrogenComponentSchema = { type: "button", title: "Button", diff --git a/app/components/Section.tsx b/app/components/Section.tsx index bb3c1b04..c0df560c 100644 --- a/app/components/Section.tsx +++ b/app/components/Section.tsx @@ -5,13 +5,13 @@ import { import clsx from "clsx"; import type { HTMLAttributes } from "react"; import React, { forwardRef } from "react"; +import { removeFalsy } from "~/lib/utils"; import type { BackgroundImageProps } from "./BackgroundImage"; import { BackgroundImage, backgroundInputs } from "./BackgroundImage"; import { Overlay, overlayInputs } from "./Overlay"; export type SectionWidth = "full" | "stretch" | "fixed"; export type VerticalPadding = "none" | "small" | "medium" | "large"; -export type DividerType = "none" | "top" | "bottom" | "both"; export type SectionProps = HydrogenComponentProps & HTMLAttributes & @@ -22,7 +22,6 @@ export type SectionProps = HydrogenComponentProps & gap: number; className: string; verticalPadding: VerticalPadding; - divider: DividerType; borderRadius: number; enableOverlay: boolean; overlayColor: string; @@ -76,7 +75,6 @@ export let Section = forwardRef((props, ref) => { as: Component = "section", width, gap, - divider, verticalPadding, borderRadius, backgroundColor, @@ -97,23 +95,48 @@ export let Section = forwardRef((props, ref) => { let isBackgroundForContent = backgroundFor === "content"; return ( - <> - {(divider === "top" || divider === "both") && } - + {!isBackgroundForContent && ( + <> + + + + )} +
- {!isBackgroundForContent && ( + {isBackgroundForContent && ( <> ((props, ref) => { /> )} -
- {isBackgroundForContent && ( - <> - - - - )} - {children} -
- - {(divider === "bottom" || divider === "both") && } - + {children} +
+
); }); -function Divider() { - return
; -} - export let layoutInputs: InspectorGroup["inputs"] = [ { type: "select", @@ -206,20 +196,6 @@ export let layoutInputs: InspectorGroup["inputs"] = [ }, defaultValue: "medium", }, - { - type: "select", - name: "divider", - label: "Divider", - configs: { - options: [ - { value: "none", label: "None" }, - { value: "top", label: "Top" }, - { value: "bottom", label: "Bottom" }, - { value: "both", label: "Both" }, - ], - }, - defaultValue: "none", - }, { type: "range", name: "borderRadius", diff --git a/app/lib/utils.ts b/app/lib/utils.ts index 0cf571ce..c04c1a33 100644 --- a/app/lib/utils.ts +++ b/app/lib/utils.ts @@ -312,3 +312,24 @@ export function isLocalPath(url: string) { return false; } + +export function removeFalsy( + obj: {}, + falsyValues: any[] = ["", null, undefined], +): T { + if (!obj || typeof obj !== "object") return obj as any; + + return Object.entries(obj).reduce((a: any, c) => { + let [k, v]: [string, any] = c; + if ( + falsyValues.indexOf(v) === -1 && + JSON.stringify(removeFalsy(v, falsyValues)) !== "{}" + ) { + a[k] = + typeof v === "object" && !Array.isArray(v) + ? removeFalsy(v, falsyValues) + : v; + } + return a; + }, {}) as T; +} diff --git a/app/sections/columns-with-images/column.tsx b/app/sections/columns-with-images/column.tsx index 47b17d60..3e50912a 100644 --- a/app/sections/columns-with-images/column.tsx +++ b/app/sections/columns-with-images/column.tsx @@ -8,7 +8,7 @@ import { import clsx from "clsx"; import { forwardRef } from "react"; import type { ButtonProps } from "~/components/Button"; -import Button, { buttonInputs } from "~/components/Button"; +import Button, { buttonContentInputs } from "~/components/Button"; interface ColumnWithImageItemProps extends ButtonProps, HydrogenComponentProps { imageSrc: WeaverseImage; @@ -129,7 +129,7 @@ export let schema: HydrogenComponentSchema = { type: "heading", label: "Button (optional)", }, - ...buttonInputs, + ...buttonContentInputs, ], }, ], diff --git a/app/sections/spacer.tsx b/app/sections/spacer.tsx new file mode 100644 index 00000000..6591bf82 --- /dev/null +++ b/app/sections/spacer.tsx @@ -0,0 +1,102 @@ +import type { + HydrogenComponentProps, + HydrogenComponentSchema, +} from "@weaverse/hydrogen"; +import { forwardRef } from "react"; + +type SpacerProps = HydrogenComponentProps & { + mobileHeight: number; + desktopHeight: number; + backgroundColor: string; + addSeparator: boolean; + separatorColor: string; +}; + +let Spacer = forwardRef((props, ref) => { + let { + mobileHeight, + desktopHeight, + backgroundColor, + addSeparator, + separatorColor, + ...rest + } = props; + return ( +
+ {addSeparator && ( +
+ )} +
+ ); +}); + +export default Spacer; + +export let schema: HydrogenComponentSchema = { + type: "spacer", + title: "Spacer", + inspector: [ + { + group: "Spacer", + inputs: [ + { + type: "range", + label: "Mobile height", + name: "mobileHeight", + configs: { + min: 0, + max: 200, + step: 1, + unit: "px", + }, + defaultValue: 50, + helpText: "Set to 0 to hide the Spacer on mobile devices", + }, + { + type: "range", + label: "Desktop height", + name: "desktopHeight", + configs: { + min: 0, + max: 300, + step: 1, + unit: "px", + }, + defaultValue: 100, + }, + { + type: "color", + label: "Background color", + name: "backgroundColor", + defaultValue: "#00000000", + }, + { + type: "switch", + label: "Add border separator", + name: "addSeparator", + defaultValue: false, + }, + { + type: "color", + label: "Separator color", + name: "separatorColor", + defaultValue: "#000", + condition: "addSeparator.eq.true", + }, + ], + }, + ], + toolbar: ["general-settings", ["duplicate", "delete"]], +}; diff --git a/app/styles/app.css b/app/styles/app.css index e169fa66..60d2e5dd 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -47,7 +47,9 @@ h3, h4, h5, - h6 { + h6, + a, + button { @apply font-sans; } diff --git a/app/weaverse/components.ts b/app/weaverse/components.ts index d5ac11df..015b472c 100644 --- a/app/weaverse/components.ts +++ b/app/weaverse/components.ts @@ -46,6 +46,7 @@ import * as TestimonialItems from "~/sections/testimonials/items"; import * as UserProfiles from "~/sections/user-profiles"; import * as VideoEmbed from "~/sections/video-embed"; import * as VideoEmbedItem from "~/sections/video-embed/video"; +import * as Spacer from "~/sections/spacer"; export let components: HydrogenComponent[] = [ ...sharedComponents, @@ -97,4 +98,5 @@ export let components: HydrogenComponent[] = [ SlideShowItem, ProductList, ContactForm, + Spacer, ];