Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AccessPackageListItem): Adding list-item components for access-packages and access-areas #139

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 18 additions & 0 deletions lib/components/AccessAreaList/AccessAreaList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { ListBase, type ListTheme } from '../List';
import { AccessAreaListItem, type AccessAreaListItemProps } from './AccessAreaListItem';

export interface AccessAreaListProps {
items: AccessAreaListItemProps[];
theme?: ListTheme;
}

export const AccessAreaList = ({ items, theme }: AccessAreaListProps) => {
return (
<ListBase theme={theme} spacing="xs">
{items.map((item) => (
<AccessAreaListItem {...item} key={item.id} {...item} />
))}
</ListBase>
);
};
79 changes: 79 additions & 0 deletions lib/components/AccessAreaList/AccessAreaListItem.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { AccessAreaListItem } from './AccessAreaListItem';

import areaGroups from '../../../test-data/accesspackages.json';
import { AccessPackageList } from '../AccessPackageList/AccessPackageList';

const testArea = areaGroups[1].areas[1];

const children = (
<>
{testArea.description && <p>{testArea.description}</p>}
<AccessPackageList
items={testArea.packages.map((p) => ({
id: p.id,
title: p.name,
}))}
/>
</>
);

const meta = {
title: 'List/AccessAreaListItem',
component: AccessAreaListItem,
tags: ['autodocs'],
args: {
id: testArea.id,
size: 'md',
name: testArea.name,
icon: `data:image/svg+xml;base64,${btoa(testArea.icon)}`,
children,
},
argTypes: {
sonwit marked this conversation as resolved.
Show resolved Hide resolved
size: {
options: ['sm', 'md', 'lg'],
control: {
type: 'inline-radio',
},
},
},
} satisfies Meta<typeof AccessAreaListItem>;

export default meta;
type Story = StoryObj<typeof meta>;

export const AreaListItemStory: Story = {};

export const AllAreas = (args) => {
const [expanded, setExpanded] = React.useState<string | null>(null);
return (
<div>
{areaGroups.map((group) => (
<div key={group.id} style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
<h2>{group.name}</h2>
<p>{group.description}</p>
{group.areas.map((area) => (
<AccessAreaListItem
id={area.id}
key={area.id}
name={area.name}
icon={`data:image/svg+xml;base64,${btoa(area.icon)}`}
size={args.size}
expanded={expanded === area.id}
onClick={() => setExpanded((prev) => (prev === area.id ? null : area.id))}
>
{area.description && <p>{area.description}</p>}
<AccessPackageList
items={area.packages.map((p) => ({
id: p.id,
title: p.name,
}))}
/>
</AccessAreaListItem>
))}
</div>
))}
</div>
);
};
40 changes: 40 additions & 0 deletions lib/components/AccessAreaList/AccessAreaListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ListItemBase, ListItemHeader } from '../List';
import type { ListItemProps } from '../List';
import styles from './accessAreaListItem.module.css';

export interface AccessAreaListItemProps extends Pick<ListItemProps, 'size' | 'onClick' | 'expanded'> {
id: string;
name: string;
icon: string;
children?: React.ReactNode;
}

export const AccessAreaListItem = ({
name,
icon,
size = 'md',
children,
expanded = false,
onClick,
...props
}: AccessAreaListItemProps) => {
return (
<ListItemBase size={size} color="subtle" expanded={expanded}>
<ListItemHeader
as="button"
avatar={{
name,
imageUrl: icon,
type: 'company',
}}
title={name}
size={size}
collapsible={true}
expanded={expanded}
onClick={onClick}
{...props}
/>
{expanded && <div className={styles.content}>{children}</div>}
</ListItemBase>
);
};
4 changes: 4 additions & 0 deletions lib/components/AccessAreaList/accessAreaListItem.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.content {
padding: 0.625rem;
padding-top: 0;
}
1 change: 1 addition & 0 deletions lib/components/AccessAreaList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AccessAreaListItem.tsx';
24 changes: 24 additions & 0 deletions lib/components/AccessPackageList/AccessPackageList.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import areaGroups from '../../../test-data/accesspackages.json';
import { AccessPackageList } from './AccessPackageList';

const testArea = areaGroups[0].areas[1];

const meta = {
title: 'List/AccessPackageList',
component: AccessPackageList,
tags: ['autodocs'],
args: {
items: testArea.packages.map((p) => ({
id: p.id,
title: p.name,
})),
},
} satisfies Meta<typeof AccessPackageList>;

export default meta;
type Story = StoryObj<typeof meta>;

export const AccessPackageListStory: Story = {};
16 changes: 16 additions & 0 deletions lib/components/AccessPackageList/AccessPackageList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ListBase, type ListBaseProps } from '../List';
import { AccessPackageListItem, type AccessPackageListItemProps } from './AccessPackageListItem';

export interface AccessPackageListProps extends Pick<ListBaseProps, 'spacing' | 'theme'> {
items: AccessPackageListItemProps[];
}

export const AccessPackageList = ({ items, spacing = 'sm', ...props }: AccessPackageListProps) => {
return (
<ListBase spacing={spacing} {...props}>
{items.map((item) => (
<AccessPackageListItem {...item} key={item.id} {...item} />
))}
</ListBase>
);
};
28 changes: 28 additions & 0 deletions lib/components/AccessPackageList/AccessPackageListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ListItem, type ListItemProps } from '../List';

export interface AccessPackageListItemProps
extends Pick<ListItemProps, 'onClick' | 'as' | 'title' | 'description' | 'size' | 'controls'> {
id: string;
icon?: string;
}

export const AccessPackageListItem = ({ as = 'button', icon, title, ...props }: AccessPackageListItemProps) => {
return (
<ListItem
avatar={
icon
? {
imageUrl: icon,
type: 'company',
name: title || '',
}
: undefined
}
as={as}
size="sm"
color="accent"
title={title}
{...props}
/>
);
};
2 changes: 2 additions & 0 deletions lib/components/AccessPackageList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './AccessPackageListItem';
export * from './AccessPackageList';
12 changes: 4 additions & 8 deletions lib/components/ResourceList/ResourceListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { ListItem } from '../List';
import type { ListItemSize } from '../List';
import type { ListItemProps } from '../List';

export interface ResourceListItemProps {
export interface ResourceListItemProps extends Pick<ListItemProps, 'size' | 'controls' | 'as' | 'onClick'> {
id: string;
ownerName: string;
resourceName: string;
ownerLogoUrl?: string;
ownerLogoUrlAlt?: string;
size?: ListItemSize;
controls?: React.ReactNode;
}

export const ResourceListItem = ({
ownerName,
resourceName,
ownerLogoUrlAlt,
ownerLogoUrl,
size = 'md',
controls,
...props
}: ResourceListItemProps) => {
return (
<ListItem
Expand All @@ -29,8 +26,7 @@ export const ResourceListItem = ({
}}
title={resourceName}
description={ownerName}
size={size}
controls={controls}
{...props}
/>
);
};
2 changes: 2 additions & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export * from './Page';
export * from './Transmission';
export * from './Typography';
export * from './ResourceList';
export * from './AccessAreaList';
export * from './AccessPackageList';
Loading
Loading