Skip to content

Commit

Permalink
fix: move remove and save button to items for bookmark + add as prope…
Browse files Browse the repository at this point in the history
…rty for more flexibility of ListItemHeader
  • Loading branch information
seanes committed Jan 7, 2025
1 parent 571314e commit 86dc7d9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 18 deletions.
3 changes: 1 addition & 2 deletions lib/components/Bookmarks/BookmarksListItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BookmarksListItem } from './BookmarksListItem';
const meta = {
title: 'Bookmarks/BookmarksListItem',
component: BookmarksListItem,
tags: ['autodocs', 'outdated'],
tags: ['autodocs'],
parameters: {},
args: {
id: 'id',
Expand All @@ -18,7 +18,6 @@ const meta = {
label: 'Skatteetaten',
},
],
href: '#',
},
} satisfies Meta<typeof BookmarksListItem>;

Expand Down
4 changes: 4 additions & 0 deletions lib/components/Bookmarks/BookmarksListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface BookmarksListItemProps extends ListItemInputProps {
saveButton?: ButtonProps;
/** Delete button */
removeButton?: ButtonProps;
/** Render as **/
as?: React.ElementType;
}

interface FormData {
Expand All @@ -52,6 +54,7 @@ export const BookmarksListItem = ({
onToggle,
saveButton,
removeButton,
as,
...rest
}: BookmarksListItemProps) => {
const [formData, setFormData] = useState<FormData>({ title, params });
Expand Down Expand Up @@ -95,6 +98,7 @@ export const BookmarksListItem = ({
return (
<ListItemBase {...rest} loading={loading} expanded={expanded}>
<ListItemHeader
as={as}
size={size}
title={title}
loading={loading}
Expand Down
74 changes: 68 additions & 6 deletions lib/components/Bookmarks/BookmarksSection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ const meta = {
placeholder: 'Uten tittel',
helperText: 'Gi bokmerket et navn.',
},
saveButton: {
label: 'Lagre endringer',
},
removeButton: {
label: 'Slett bokmerke',
},
description: 'Sist oppdatert 3 minutter siden',
items: [
{
id: 'bookmark-1',
title: 'Mitt eget søk',
saveButton: {
label: 'Lagre søk',
},
removeButton: {
label: 'Slett',
onClick: () => {
alert('Slett bokmerket 1');
},
},
params: [
{ type: 'search', label: 'Skatt' },
{ type: 'filter', label: 'Under arbeid' },
Expand All @@ -37,13 +40,28 @@ const meta = {
{ type: 'search', label: 'Skatt' },
{ type: 'filter', label: 'Under arbeid' },
],
saveButton: {
label: 'Lagre søk',
},
removeButton: {
label: 'Slett',
onClick: () => {
alert('Slett bokmerket 2');
},
},
},
{
id: 'bookmark-3',
params: [
{ type: 'filter', label: 'Brønnøysundregistrene' },
{ type: 'filter', label: 'Krever handling' },
],
saveButton: {
label: 'Lagre søk',
},
removeButton: {
label: 'Slett',
},
},
],
},
Expand Down Expand Up @@ -94,3 +112,47 @@ export const EmptyState: Story = {
items: [],
},
};

export const AsLink: Story = {
args: {
title: '2 lagrede søk',
untitled: 'Uten tittel',
titleField: {
label: 'Tittel',
placeholder: 'Uten tittel',
helperText: 'Gi bokmerket et navn.',
},
description: 'Sist oppdatert 3 minutter siden',
items: [
{
id: 'bookmark-1',
title: 'Mitt eget søk',
saveButton: {
label: 'Lagre søk',
},
removeButton: {
label: 'Slett',
},
as: (props) => <a {...props} href="#bookmark-1" />,
params: [
{ type: 'search', label: 'Skatt' },
{ type: 'filter', label: 'Under arbeid' },
],
},
{
id: 'bookmark-2',
as: (props) => <a {...props} href="#bookmark-2" />,
params: [
{ type: 'search', label: 'Skatt' },
{ type: 'filter', label: 'Under arbeid' },
],
saveButton: {
label: 'Lagre søk',
},
removeButton: {
label: 'Slett',
},
},
],
},
};
8 changes: 1 addition & 7 deletions lib/components/Bookmarks/BookmarksSection.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { BookmarksListItem, Heading, ListBase, Section, Typography } from '../';
import type { BookmarksListItemProps, ButtonProps, TextFieldProps } from '../';
import type { BookmarksListItemProps, TextFieldProps } from '../';

export interface BookmarksSectionProps {
title?: string;
description?: string;
items: BookmarksListItemProps[];
untitled?: string;
titleField?: TextFieldProps;
saveButton?: ButtonProps;
removeButton?: ButtonProps;
expandedId?: string;
onToggle?: (id: string) => void;
loading?: boolean;
Expand All @@ -21,8 +19,6 @@ export const BookmarksSection = ({
items,
untitled = 'Untitled bookmark',
titleField,
saveButton,
removeButton,
expandedId,
onToggle,
}: BookmarksSectionProps) => {
Expand All @@ -40,8 +36,6 @@ export const BookmarksSection = ({
expanded={expandedId === item.id}
untitled={untitled}
titleField={titleField}
saveButton={saveButton}
removeButton={removeButton}
/>
))}
</ListBase>
Expand Down
9 changes: 6 additions & 3 deletions lib/components/List/ListItemBase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactNode } from 'react';
import type { ElementType, ReactNode } from 'react';
import styles from './listItemBase.module.css';

export type ListItemSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
Expand All @@ -19,6 +19,7 @@ export interface ListItemBaseProps {
selected?: boolean;
expanded?: boolean;
children?: ReactNode;
as?: ElementType;
}

export const ListItemBase = ({
Expand All @@ -33,9 +34,11 @@ export const ListItemBase = ({
selected,
expanded,
children,
as,
}: ListItemBaseProps) => {
const Component = as || 'article';
return (
<article
<Component
className={styles.item}
data-variant={variant}
data-color={color}
Expand All @@ -48,6 +51,6 @@ export const ListItemBase = ({
aria-expanded={expanded}
>
{children}
</article>
</Component>
);
};

0 comments on commit 86dc7d9

Please sign in to comment.