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

Feature/list: add linkTag to ListItem #912

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/weak-tomatoes-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@westpac/ui': minor
---

List component with custom component tag
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { styles as itemStyles } from './list-item.styles.js';
import { type ListItemProps } from './list-item.types.js';

export function BaseListItem(
{ className, children, href, target, look, type, spacing, icon, ...props }: ListItemProps,
{ className, linkTag: LinkTag = 'a', children, href, target, look, type, spacing, icon, ...props }: ListItemProps,
ref: Ref<HTMLAnchorElement>,
) {
const state = useContext(ListContext);
Expand Down Expand Up @@ -45,9 +45,9 @@ export function BaseListItem(
<li className={styles.base({ className })} {...props} key={state.nested}>
{bulletToRender()}
{type === 'link' ? (
<a href={href} target={target} className={styles.link()} ref={ref} {...focusProps}>
<LinkTag href={href} target={target} className={styles.link()} ref={ref} {...focusProps}>
{children}
</a>
</LinkTag>
) : (
children
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HTMLAttributeAnchorTarget, HTMLAttributes, ReactNode } from 'react';
import { HTMLAttributeAnchorTarget, HTMLAttributes, ReactElement, ReactNode } from 'react';

import { IconProps } from '../../../icon/index.js';

Expand All @@ -15,6 +15,10 @@ export type ListItemProps = {
* The icon for list item
*/
icon?: (props: IconProps) => JSX.Element;
/**
* Link tag to render
*/
linkTag?: 'a' | ((...args: any[]) => ReactElement | null);
/**
* The look of the bullet, icon, tick and cross lists
*/
Expand Down
26 changes: 26 additions & 0 deletions packages/ui/src/components/list/list.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,29 @@ export const Spacing = () => (
</List>
</div>
);

const CustomLink = (props: any) => {
// eslint-disable-next-line no-console
console.info('TEST');
return <a {...props}>{props.children}</a>;
};

/**
* Custom Component
*/
export const CustomComponent = () => (
<div>
<h1 className="typography-body-10 mb-2">Title</h1>
<List type="link" className="mb-4" spacing="medium">
<ListItem linkTag={CustomLink} href="#href1">
Styled bullet list
</ListItem>
<ListItem linkTag={CustomLink} href="#href2">
Styled bullet list
</ListItem>
<ListItem linkTag={CustomLink} href="#href3">
Styled bullet list
</ListItem>
</List>
</div>
);
Loading