Skip to content

Commit

Permalink
Merge pull request #852 from WestpacGEL/feature/site-feature-availabi…
Browse files Browse the repository at this point in the history
…lity-component

Availability content component for site
  • Loading branch information
jaortiz authored Sep 2, 2024
2 parents 941126e + 180ca7a commit 959f833
Show file tree
Hide file tree
Showing 53 changed files with 650 additions and 2,512 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client';

import React from 'react';

import { styles as AvailabilityContentStyles } from './availability-content.styles';
import { TableOfAvailability } from './components/table-of-availability';

import { AvailabilityContentProps } from '.';

export function AvailabilityContent({
availableGel,
availableMesh,
availableLegacyWdp,
alternativeGel,
alternativeMesh,
alternativeLegacyWdp,
}: AvailabilityContentProps) {
const styles = AvailabilityContentStyles({});
return (
<div className={styles.contentContainer({})}>
<div className={styles.tableContainer({})}>
<TableOfAvailability
availableGel={availableGel}
availableMesh={availableMesh}
availableLegacyWdp={availableLegacyWdp}
alternativeGel={alternativeGel}
alternativeMesh={alternativeMesh}
alternativeLegacyWdp={alternativeLegacyWdp}
></TableOfAvailability>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { NotEditable, component, fields } from '@keystatic/core';

const availabilityOptions = [
{ label: 'Available', value: 'available' },
{ label: 'Not Available', value: 'unavailable' },
{ label: 'In Progress', value: 'in-progress' },
];

export const availabilityContent = component({
preview: () => (
<NotEditable>
<div>Platform Availability</div>
</NotEditable>
),
label: 'Content Availability',
schema: {
availableGel: fields.select({
label: 'GEL Availability',
options: availabilityOptions,
defaultValue: 'available',
}),
availableMesh: fields.select({
label: 'Mesh Availability',
options: availabilityOptions,
defaultValue: 'available',
}),
availableLegacyWdp: fields.select({
label: 'Legacy WDP Availability',
options: availabilityOptions,
defaultValue: 'available',
}),
alternativeMesh: fields.text({
label: 'Mesh Alternative Name',
multiline: false,
defaultValue: undefined,
}),
alternativeLegacyWdp: fields.text({
label: 'Legacy WDP Alternative Name',
multiline: false,
defaultValue: undefined,
}),
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { tv } from 'tailwind-variants';

export const styles = tv({
slots: {
contentContainer: 'mb-5 mt-4 max-w-5xl bg-white p-6 pb-0',
tableContainer: 'relative -mx-6 -mt-6 border-muted-50 px-6 pb-6 pt-9',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DocumentElement } from '@keystatic/core';

export type AvailabilitySectionProps = { content: DocumentElement[]; title: string };

export type AvailabilityContentProps = {
alternativeGel?: string;
alternativeLegacyWdp?: string;
alternativeMesh?: string;
availableGel: string;
availableLegacyWdp: string;
availableMesh: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './table-of-availability/table-of-availability.component';
export * from './table-of-availability/table-of-availability.types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './table-of-availability.component';
export * from './table-of-availability.types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use client';

import { Table, TableBody, TableCell, TableHeader, TableHeaderCell, TableHeaderRow, TableRow } from '@westpac/ui';
import { CalendarIcon, TickCircleIcon, WarningIcon } from '@westpac/ui/icon';
import React from 'react';

import { styles as TableOfAvailabilityStyles } from './table-of-availability.styles';

interface TableOfAvailabilityProps {
alternativeGel?: string;
alternativeLegacyWdp?: string;
alternativeMesh?: string;
availableGel: string;
availableLegacyWdp: string;
availableMesh: string;
}

const availabilityMap: Record<
string,
{ color: 'success' | 'warning' | 'info'; icon: React.ElementType; text: string }
> = {
available: { text: 'Available', icon: TickCircleIcon, color: 'success' },
unavailable: { text: 'Older version available', icon: WarningIcon, color: 'warning' },
'in-progress': { text: 'Older version available - Upgrade in backlog', icon: CalendarIcon, color: 'info' },
};

export function TableOfAvailability({
availableGel,
availableMesh,
availableLegacyWdp,
alternativeGel,
alternativeMesh,
alternativeLegacyWdp,
}: TableOfAvailabilityProps) {
const platforms = [
{ name: 'GEL Design System', status: availableGel, alternative: alternativeGel },
{ name: 'Mesh UI', status: availableMesh, alternative: alternativeMesh },
{ name: 'Legacy WDP', status: availableLegacyWdp, alternative: alternativeLegacyWdp },
];

const styles = TableOfAvailabilityStyles({});

const hasAlternativeNames = platforms.some(platform => platform.alternative);
const cellWidth = hasAlternativeNames ? '33%' : '50%';

return (
<Table>
<TableHeader>
<TableHeaderRow>
<TableHeaderCell>Platform</TableHeaderCell>
<TableHeaderCell>Status</TableHeaderCell>
{hasAlternativeNames && <TableHeaderCell>Other name</TableHeaderCell>}
</TableHeaderRow>
</TableHeader>
<TableBody>
{platforms.map(platform => {
const { text, icon: Icon, color } = availabilityMap[platform.status];
return (
<TableRow key={platform.name}>
<TableCell width={cellWidth}>
<strong>{platform.name}</strong>
</TableCell>
<TableCell width={cellWidth}>
<div className={styles.text({ color })}>
<Icon size="small" look="outlined" className="mr-2" color={color} />
{text}
</div>
</TableCell>
{hasAlternativeNames && <TableCell width={cellWidth}>{platform.alternative || ''}</TableCell>}
</TableRow>
);
})}
</TableBody>
</Table>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { tv } from 'tailwind-variants';

export const styles = tv({
slots: {
text: 'typography-body-10',
},
variants: {
color: {
success: {
text: 'text-success',
},
warning: {
text: 'text-warning',
},
info: {
text: 'text-info',
},
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';

export type TableOfAvailabilityProps = {
availableGel: string;
availableLegacyWdp: string;
availableMesh: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './availability-content.component';
export * from './availability-content.types';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Image } from '@/components/document-renderer';
import { Colors } from './colors/colors.component';
import { colors } from './colors/colors.preview';
import { accessibilityDemo } from './components/accessibility-demo/accessibility-demo.preview';
import { AvailabilityContent } from './components/availability-content/availability-content.component';
import { availabilityContent } from './components/availability-content/availability-content.preview';
import { designSystemBodyImage } from './components/design-system-body-image';
import { LinkList } from './components/link-list';
import { linkList } from './components/link-list/link-list.preview';
Expand All @@ -29,6 +31,7 @@ export const foundationBlocks = {
linkList,
shortCode,
accessibilityDemo,
availabilityContent,
};

export const foundationBlocksComponents = {
Expand All @@ -44,4 +47,5 @@ export const foundationBlocksComponents = {
<Image {...props} />
</div>
),
availabilityContent: (props: any) => <AvailabilityContent {...props} />,
};
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
{% shortCode name="where-is-this-available" /%}

```tsx
<Table>

<React.Fragment key=".0">
<TableHeader>
<TableHeaderRow>
<TableHeaderCell>
Platform
</TableHeaderCell>
<TableHeaderCell>
Status
</TableHeaderCell>

</TableHeaderRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>
<strong>GEL Design System</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
<TableRow>
<TableCell>
<strong>Mesh UI</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
<TableRow>
<TableCell>
<strong>Legacy WDP</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
</TableBody>

</React.Fragment>
</Table>
```
{% availabilityContent
availableGel="available"
availableMesh="available"
availableLegacyWdp="available" /%}
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
{% shortCode name="where-is-this-available" /%}

```tsx
<Table colspan={2}>

<React.Fragment key=".0">
<TableHeader>
<TableHeaderRow>
<TableHeaderCell>
Platform
</TableHeaderCell>
<TableHeaderCell>
Status
</TableHeaderCell>

</TableHeaderRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>
<strong>GEL Design System</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
<TableRow>
<TableCell>
<strong>Mesh UI</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
<TableRow>
<TableCell>
<strong>Legacy WDP</strong>
</TableCell>
<TableCell>
<div className="typography-body-10 text-success"><TickCircleIcon size="small" look="outlined" className="mr-2" />Available</div>
</TableCell>

</TableRow>
</TableBody>

</React.Fragment>
</Table>
```
{% availabilityContent
availableGel="available"
availableMesh="available"
availableLegacyWdp="available" /%}
Loading

0 comments on commit 959f833

Please sign in to comment.