Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"prettier": "npx prettier . --write"
},
"dependencies": {
"@abgov/react-components": "6.10.0-dev.8",
"@abgov/ui-components-common": "1.10.0-dev.2",
"@abgov/web-components": "1.40.0-dev.17",
"@abgov/react-components": "6.10.0-next.1",
"@abgov/ui-components-common": "1.10.0-next.1",
"@abgov/web-components": "1.40.0-next.1",
"@faker-js/faker": "^8.3.1",
"highlight.js": "^11.8.0",
"js-cookie": "^3.0.5",
Expand Down
34 changes: 22 additions & 12 deletions src/components/sandbox/Sandbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type Flag = "reactive" | "template-driven" | "event";
type ComponentType = "goa" | "codesnippet";
type Serializer = (el: any, properties: ComponentBinding[]) => string;

interface SandboxProps {
interface SandboxProps<T = Record<string, unknown>> {
properties?: ComponentBinding[];
formItemProperties?: ComponentBinding[];
note?: string | { type?: GoabCalloutType; heading?: string; content: string };
fullWidth?: boolean;
onChange?: (bindings: ComponentBinding[], props: Record<string, unknown>) => void;
onChange?: (bindings: ComponentBinding[], props: T) => void;
onChangeFormItemBindings?: (bindings: ComponentBinding[], props: Record<string, unknown>) => void;
flags?: Flag[];
skipRender?: boolean; // prevent rendering the snippet, to allow custom code to be shown
Expand All @@ -41,11 +41,11 @@ interface SandboxProps {

type SandboxViewProps = {
fullWidth?: boolean;
sandboxProps: SandboxProps;
sandboxProps: SandboxProps<unknown>;
background?: string;
};

export const Sandbox = (props: SandboxProps) => {
export const Sandbox = <T = Record<string, unknown>,>(props: SandboxProps<T>) => {
const {language: lang, version} = useContext(LanguageVersionContext);
const [formatLang, setFormatLang] = useState<string>("");

Expand Down Expand Up @@ -92,10 +92,20 @@ export const Sandbox = (props: SandboxProps) => {
}

function onChangeFormItemBindings(bindings: ComponentBinding[]) {
props.onChangeFormItemBindings?.(bindings, toKeyValue(bindings));
props.onChangeFormItemBindings?.(bindings, toFormItemKeyValue(bindings));
}

function toKeyValue(bindings: ComponentBinding[]) {
function toKeyValue(bindings: ComponentBinding[]): T {
return bindings.reduce((acc: Record<string, unknown>, prop: ComponentBinding) => {
if (typeof prop.value === "string" && prop.value === "") {
return acc;
}
acc[prop.name] = prop.value;
return acc;
}, {}) as unknown as T;
}

function toFormItemKeyValue(bindings: ComponentBinding[]): Record<string, unknown> {
return bindings.reduce((acc: Record<string, unknown>, prop: ComponentBinding) => {
if (typeof prop.value === "string" && prop.value === "") {
return acc;
Expand All @@ -117,7 +127,7 @@ export const Sandbox = (props: SandboxProps) => {

return (
<>
{props.skipRenderDom ? null : <SandboxView fullWidth={props.fullWidth} sandboxProps={props} background={props.background} />}
{props.skipRenderDom ? null : <SandboxView fullWidth={props.fullWidth} sandboxProps={props as SandboxProps<unknown>} background={props.background} />}

{/* Only render the GoAAccordion if props.properties is provided */}
{props.properties && props.properties.length > 0 && (
Expand All @@ -141,7 +151,7 @@ export const Sandbox = (props: SandboxProps) => {
/>
</GoabAccordion>
)}
<SandboxCode props={props} formatLang={formatLang} lang={lang} serializers={serializers} version={version} />
<SandboxCode props={props as SandboxProps<unknown>} formatLang={formatLang} lang={lang} serializers={serializers} version={version} />
{props.note &&
(typeof props.note === "string" ? (
<p className="sandbox-note">{props.note}</p>
Expand All @@ -162,7 +172,7 @@ export const Sandbox = (props: SandboxProps) => {
};

type SandboxCodeProps = {
props: SandboxProps & { children: ReactNode };
props: SandboxProps<unknown> & { children: ReactNode };
lang: string;
formatLang: string;
serializers: Record<string, Serializer>;
Expand Down Expand Up @@ -246,7 +256,7 @@ function SandboxCode(p: SandboxCodeProps) {
// to be displayed, while hiding the non-reactive ones
type AdditionalCodeSnippetsProps = {
tags: string[];
sandboxProps: SandboxProps;
sandboxProps: SandboxProps<unknown>;
}
function AdditionalCodeSnippets(props: AdditionalCodeSnippetsProps) {
const matches = (list: string[]): boolean => {
Expand All @@ -269,7 +279,7 @@ function AdditionalCodeSnippets(props: AdditionalCodeSnippetsProps) {
// Filters components from within the Sandbox children
// i.e. Get all the <CodeSnippet> components
type ComponentListProps = {
sandboxProps: SandboxProps;
sandboxProps: SandboxProps<unknown>;
type: ComponentType;
}
function ComponentList(props: ComponentListProps): ReactElement[] {
Expand All @@ -289,7 +299,7 @@ function ComponentList(props: ComponentListProps): ReactElement[] {
type ComponentOutputProps = {
formatLang: string;
type: "angular" | "angular-reactive" | "angular-template-driven" | "react";
sandboxProps: SandboxProps;
sandboxProps: SandboxProps<unknown>;
serializer: Serializer;
}

Expand Down
8 changes: 2 additions & 6 deletions src/examples/show-links-to-navigation-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import { propsToString } from "@components/sandbox/BaseSerializer.ts";

type FooterNavPropsType = GoabFooterNavSectionProps;
type FooterPropsType = GoabAppFooterProps;
type CastingType = {
// add any required props here
[key: string]: unknown;
};

export const ShowLinksToNavigationItems = () => {
const {version} = useContext(LanguageVersionContext);
Expand Down Expand Up @@ -55,8 +51,8 @@ export const ShowLinksToNavigationItems = () => {
maxColumnCount: props.maxColumnCount || 1
};

setFooterProps(footerProps as CastingType);
setFooterNavSectionProps(footerNavSectionProps as CastingType);
setFooterProps(footerProps as FooterPropsType);
setFooterNavSectionProps(footerNavSectionProps as FooterNavPropsType);
setAppFooterNavBindings(bindings);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSandboxFormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useSandboxFormItem = (initialProps: GoabFormItemProps) => {

function onFormItemChange(bindings: ComponentBinding[], props: Record<string, unknown>) {
setFormItemBindings(bindings);
setFormItemProps(props);
setFormItemProps(props as GoabFormItemProps);
}

return { formItemBindings, formItemProps, onFormItemChange };
Expand Down
13 changes: 3 additions & 10 deletions src/routes/components/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Category, ComponentHeader } from "@components/component-header/Componen
import { useState } from "react";
import AccordionExamples from "@examples/accordion/AccordionExamples.tsx";
import { ComponentContent } from "@components/component-content/ComponentContent";
import { GoabAccordionHeadingSize } from "@abgov/ui-components-common";
import {
LegacyMarginProperty,
LegacyTestIdProperties,
Expand All @@ -35,12 +34,6 @@ const FIGMA_LINK = "https://www.figma.com/design/3pb2IK8s2QUqWieH79KdN7/%E2%9D%9


type ComponentPropsType = GoabAccordionProps;
type CastingType = {
heading: string;
headingSize: GoabAccordionHeadingSize;
children: React.ReactNode;
[key: string]: unknown;
};

export default function AccordionPage() {

Expand Down Expand Up @@ -215,9 +208,9 @@ export default function AccordionPage() {
MarginProperty,
];

function onSandboxChange(bindings: ComponentBinding[], props: Record<string, unknown>) {
function onSandboxChange(bindings: ComponentBinding[], props: ComponentPropsType) {
setAccordionBindings(bindings);
setAccordionProps(props as CastingType);
setAccordionProps(props);
}

return (
Expand All @@ -237,7 +230,7 @@ export default function AccordionPage() {
<h2 id="component" style={{ display: "none" }}>
Playground
</h2>
<Sandbox properties={accordionBindings} onChange={onSandboxChange} fullWidth>
<Sandbox<ComponentPropsType> properties={accordionBindings} onChange={onSandboxChange} fullWidth>
<GoabAccordion {...accordionProps}>
This is the content in an accordion item. This content can be anything that you want including rich
text, components, and more.
Expand Down
11 changes: 3 additions & 8 deletions src/routes/components/AppFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ const relatedComponents = [
];
type ComponentPropsType = GoabAppFooterProps;

type CastingType = {
// add any required props here
[key: string]: unknown;
};

export default function AppFooterPage() {
const {language} = useContext(LanguageVersionContext);

Expand Down Expand Up @@ -88,8 +83,8 @@ export default function AppFooterPage() {
},
];

function onSandbox1Change(bindings: ComponentBinding[], props: Record<string, unknown>) {
setSandbox1Props(props as CastingType);
function onSandbox1Change(bindings: ComponentBinding[], props: ComponentPropsType) {
setSandbox1Props(props);
setAppFooterBindings(bindings);
}

Expand All @@ -110,7 +105,7 @@ export default function AppFooterPage() {
Playground
</h2>
<h3>Basic Footer</h3>
<Sandbox properties={appFooterBindings} onChange={onSandbox1Change} fullWidth>
<Sandbox<ComponentPropsType> properties={appFooterBindings} onChange={onSandbox1Change} fullWidth>
<GoabAppFooter {...sandbox1Props} />
</Sandbox>

Expand Down
10 changes: 3 additions & 7 deletions src/routes/components/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ const relatedComponents = [
{ link: "/components/microsite-header", name: "Microsite header" }
];
type ComponentPropsType = GoabAppHeaderProps;
type CastingType = {
// add any required props here
[key: string]: unknown;
};
export default function AppHeaderPage() {
const [appHeaderProps, setAppHeaderProps] = useState<ComponentPropsType>({
url: "www.alberta.ca",
Expand Down Expand Up @@ -185,8 +181,8 @@ export default function AppHeaderPage() {
];


function onSandboxChange(bindings: ComponentBinding[], props: Record<string, unknown>) {
setAppHeaderProps(props as CastingType);
function onSandboxChange(bindings: ComponentBinding[], props: ComponentPropsType) {
setAppHeaderProps(props);
setAppHeaderBindings(bindings);
}

Expand All @@ -207,7 +203,7 @@ export default function AppHeaderPage() {
<h2 id="component" style={{ display: "none" }}>
Playground
</h2>
<Sandbox properties={appHeaderBindings} onChange={onSandboxChange} fullWidth>
<Sandbox<ComponentPropsType> properties={appHeaderBindings} onChange={onSandboxChange} fullWidth>
<GoabAppHeader {...appHeaderProps} />
</Sandbox>

Expand Down
Loading