From 9757f5dda9827e18b77e7e942517b04cc0bae3da Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Mon, 12 Feb 2024 13:39:43 +0100 Subject: [PATCH] feat: add cva --- components/Current/Blocks/List/ListItem.tsx | 81 +++++++++++++++++++++ components/Current/Blocks/List/index.tsx | 79 +------------------- package-lock.json | 20 +++++ package.json | 1 + 4 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 components/Current/Blocks/List/ListItem.tsx diff --git a/components/Current/Blocks/List/ListItem.tsx b/components/Current/Blocks/List/ListItem.tsx new file mode 100644 index 000000000..601c50ec5 --- /dev/null +++ b/components/Current/Blocks/List/ListItem.tsx @@ -0,0 +1,81 @@ +import Link from "next/link" +import { cva } from "class-variance-authority" +import { BlockListItemsEnum } from "@/types/requests/blocks/list" +import type { ListItem } from "@/types/requests/blocks/list" +import styles from "./list.module.css" + +const config = { + variants: { + type: { + default: styles.disc, + checkmark: styles.checkmark, + }, + }, + defaultVariants: { + type: "default", + }, +} as const + +const listItemStyle = cva(styles.listItem, config) + +export default function ListItem({ listItem }: { listItem: ListItem }) { + const typeName = listItem.__typename + + switch (typeName) { + case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItem: + return ( +
  • + {listItem.list_item.subtitle ? ( + <> + {listItem.list_item.title} +
    + {listItem.list_item.subtitle} + + ) : ( + listItem.list_item.title + )} +
  • + ) + case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemExternalLink: + return ( +
  • + + {listItem.list_item_external_link.link.title} + +
    + {listItem.list_item_external_link.subtitle} +
  • + ) + case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemInternalLink: + const link = listItem.list_item_internal_link.pageConnection.edges[0] + const linkUrlWithLocale = `/${link.node.system.locale}${link.node.url}` + return ( +
  • + + {listItem.list_item_internal_link.link_text} + +
    + {listItem.list_item_internal_link.subtitle} +
  • + ) + + default: + return null + } +} diff --git a/components/Current/Blocks/List/index.tsx b/components/Current/Blocks/List/index.tsx index 269108895..11e6589ec 100644 --- a/components/Current/Blocks/List/index.tsx +++ b/components/Current/Blocks/List/index.tsx @@ -1,8 +1,7 @@ -import { BlockListItemsEnum } from "@/types/requests/blocks/list" -import type { ListProps, ListItem } from "@/types/requests/blocks/list" +import type { ListProps } from "@/types/requests/blocks/list" import styles from "./list.module.css" -import Link from "next/link" +import ListItem from "./ListItem" export default function List({ list }: ListProps) { return ( @@ -16,77 +15,3 @@ export default function List({ list }: ListProps) { ) } - -function ListItem({ listItem }: { listItem: ListItem }) { - const typeName = listItem.__typename - - switch (typeName) { - case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItem: - return ( -
  • - {listItem.list_item.subtitle ? ( - <> - {listItem.list_item.title} -
    - {listItem.list_item.subtitle} - - ) : ( - listItem.list_item.title - )} -
  • - ) - case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemExternalLink: - return ( -
  • - - {listItem.list_item_external_link.link.title} - -
    - {listItem.list_item_external_link.subtitle} -
  • - ) - case BlockListItemsEnum.CurrentBlocksPageBlocksListBlockListItemsListItemInternalLink: - const link = listItem.list_item_internal_link.pageConnection.edges[0] - const linkUrlWithLocale= `/${link.node.system.locale}${link.node.url}` - return ( -
  • - - {listItem.list_item_internal_link.link_text} - -
    - {listItem.list_item_internal_link.subtitle} -
  • - ) - - default: - return null - } -} diff --git a/package-lock.json b/package-lock.json index 1cb8e28aa..d8c221c9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "web", "version": "0.1.0", "dependencies": { + "class-variance-authority": "^0.7.0", "graphql": "16.8.1", "graphql-request": "6.1.0", "graphql-tag": "2.12.6", @@ -873,11 +874,30 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/class-variance-authority": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.0.tgz", + "integrity": "sha512-jFI8IQw4hczaL4ALINxqLEXQbWcNjoSkloa4IaufXCJr6QawJyw7tuRysRsrE8w2p/4gGaxKIt/hX3qz/IbD1A==", + "dependencies": { + "clsx": "2.0.0" + }, + "funding": { + "url": "https://joebell.co.uk" + } + }, "node_modules/client-only": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==" }, + "node_modules/clsx": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.0.0.tgz", + "integrity": "sha512-rQ1+kcj+ttHG0MKVGBUXwayCCF1oh39BF5COIpRzuCEv8Mwjv0XucrI2ExNTOn9IlLifGClWQcU9BrZORvtw6Q==", + "engines": { + "node": ">=6" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", diff --git a/package.json b/package.json index 0fa8479f3..70753f7c0 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "next lint && tsc" }, "dependencies": { + "class-variance-authority": "^0.7.0", "graphql": "16.8.1", "graphql-request": "6.1.0", "graphql-tag": "2.12.6",