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

Custom Combobox content #216

Merged
merged 2 commits into from
Jan 18, 2024
Merged
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/chilly-mails-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@animareflection/ui": patch
---

Allow custom content override in `Combobox`
Binary file modified bun.lockb
Binary file not shown.
58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@ark-ui/anatomy": "^1.2.0",
"@ark-ui/react": "^1.2.1",
"@ark-ui/anatomy": "^1.3.0",
"@ark-ui/react": "^1.3.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@commitlint/types": "^18.4.3",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@commitlint/types": "^18.4.4",
"@omnidev/knit": "^0.1.2",
"@pandacss/dev": "^0.24.2",
"@pandacss/types": "^0.24.2",
"@storybook/addon-a11y": "^7.6.6",
"@pandacss/dev": "^0.27.2",
"@pandacss/types": "^0.27.2",
"@storybook/addon-a11y": "^7.6.9",
"@storybook/addon-coverage": "^1.0.0",
"@storybook/addon-essentials": "^7.6.6",
"@storybook/addon-interactions": "^7.6.6",
"@storybook/addon-links": "^7.6.6",
"@storybook/blocks": "^7.6.6",
"@storybook/builder-webpack5": "^7.6.6",
"@storybook/addon-essentials": "^7.6.9",
"@storybook/addon-interactions": "^7.6.9",
"@storybook/addon-links": "^7.6.9",
"@storybook/blocks": "^7.6.9",
"@storybook/builder-webpack5": "^7.6.9",
"@storybook/jest": "^0.2.3",
"@storybook/manager-api": "^7.6.6",
"@storybook/nextjs": "^7.6.6",
"@storybook/react": "^7.6.6",
"@storybook/manager-api": "^7.6.9",
"@storybook/nextjs": "^7.6.9",
"@storybook/react": "^7.6.9",
"@storybook/storybook-deployer": "^2.8.16",
"@storybook/test-runner": "^0.16.0",
"@storybook/testing-library": "^0.2.2",
"@storybook/theming": "^7.6.6",
"@storybook/types": "^7.6.6",
"@testing-library/dom": "^9.3.3",
"@storybook/theming": "^7.6.9",
"@storybook/types": "^7.6.9",
"@testing-library/dom": "^9.3.4",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.10.6",
"@types/react": "^18.2.46",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@types/node": "^20.11.5",
"@types/react": "^18.2.48",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -99,25 +99,25 @@
"eslint-plugin-testing-library": "^6.2.0",
"eslint-plugin-typescript-sort-keys": "^3.1.0",
"eslint-plugin-unused-imports": "^3.0.0",
"framer-motion": "^10.17.4",
"framer-motion": "^10.18.0",
"http-server": "^14.1.1",
"husky": "^8.0.3",
"jsonfile": "^6.1.0",
"lint-staged": "^15.2.0",
"next": "^14.0.4",
"postcss": "^8.4.32",
"prettier": "^3.1.1",
"postcss": "^8.4.33",
"prettier": "^3.2.4",
"radash": "^11.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-icons": "^5.0.1",
"sonner": "^1.3.1",
"storybook": "^7.6.6",
"storybook": "^7.6.9",
"storybook-dark-mode": "^3.0.3",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"usehooks-ts": "^2.9.1",
"usehooks-ts": "^2.9.4",
"wait-on": "^7.2.0",
"webpack": "^5.89.0"
}
Expand Down
90 changes: 47 additions & 43 deletions src/components/core/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ interface Group {
}

export interface Props
extends Omit<PrimitiveComboboxProps, "items">,
extends Omit<PrimitiveComboboxProps, "items" | "content">,
ComboboxVariantProps {
groups: Group[];
label: {
singular: string;
plural: string;
props?: PrimitiveComboboxLabelProps;
display?: boolean;
};
/** Custom content render override. */
content?: ReactNode;
groups: Group[];
itemIndicator?: boolean;
triggerEnabled?: boolean;
inputProps?: Omit<InputProps, "size">;
Expand All @@ -72,6 +74,7 @@ export interface Props

const Combobox = ({
label,
content,
groups = [],
itemIndicator = false,
triggerEnabled = true,
Expand Down Expand Up @@ -145,50 +148,51 @@ const Combobox = ({

<PrimitiveComboboxPositioner {...positionerProps}>
<PrimitiveComboboxContent {...contentProps}>
{groups.map(
(group) =>
group.items.some((item) => filteredItems.includes(item)) && (
<PrimitiveComboboxItemGroup
key={group.label.id}
id={group.label.id}
{...itemGroupProps}
>
{group.label.display && (
<PrimitiveComboboxItemGroupLabel
htmlFor={group.label.id}
{...group.label.props}
>
{group.label.plural}
</PrimitiveComboboxItemGroupLabel>
)}
{content ||
groups.map(
(group) =>
group.items.some((item) => filteredItems.includes(item)) && (
<PrimitiveComboboxItemGroup
key={group.label.id}
id={group.label.id}
{...itemGroupProps}
>
{group.label.display && (
<PrimitiveComboboxItemGroupLabel
htmlFor={group.label.id}
{...group.label.props}
>
{group.label.plural}
</PrimitiveComboboxItemGroupLabel>
)}

{group.items.map(
(item) =>
filteredItems.includes(item) && (
<PrimitiveComboboxItem
key={item.value}
item={item}
{...item.itemProps}
>
<Flex align="center" gap={2}>
{item.icon}
{group.items.map(
(item) =>
filteredItems.includes(item) && (
<PrimitiveComboboxItem
key={item.value}
item={item}
{...item.itemProps}
>
<Flex align="center" gap={2}>
{item.icon}

<PrimitiveComboboxItemText>
{item.label}
</PrimitiveComboboxItemText>
</Flex>
<PrimitiveComboboxItemText>
{item.label}
</PrimitiveComboboxItemText>
</Flex>

{itemIndicator && (
<PrimitiveComboboxItemIndicator>
<BiCheck />
</PrimitiveComboboxItemIndicator>
)}
</PrimitiveComboboxItem>
),
)}
</PrimitiveComboboxItemGroup>
),
)}
{itemIndicator && (
<PrimitiveComboboxItemIndicator>
<BiCheck />
</PrimitiveComboboxItemIndicator>
)}
</PrimitiveComboboxItem>
),
)}
</PrimitiveComboboxItemGroup>
),
)}
</PrimitiveComboboxContent>
</PrimitiveComboboxPositioner>
</PrimitiveCombobox>
Expand Down