Skip to content

Feature/xw 122/grouped select #166

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

Merged
merged 6 commits into from
Nov 28, 2023
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: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

- **Version 2.2 (breaking changes from 2.1.x)**

- 2.2.33: Refactored DownloadCard.
- 2.2.34:
- Added select options grouping logic.
- 2.2.33:
- Refactored DownloadCard.
- 2.2.32: Added more tokens to DownloadCard.
- 2.2.31:
- Added custom content to NotificationPopUp.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@conduction/components",
"version": "2.2.33",
"version": "2.2.34",
"description": "React (Gatsby) components used within the Conduction Skeleton Application (and its implementations)",
"main": "lib/index.js",
"scripts": {
Expand All @@ -14,12 +14,7 @@
"type": "git",
"url": "git+https://github.com/ConductionNL/conduction-components.git"
},
"keywords": [
"React",
"Gatsby",
"Conduction",
"Components"
],
"keywords": ["React", "Gatsby", "Conduction", "Components"],
"author": "Conduction B.V.",
"license": "ISC",
"bugs": {
Expand Down
10 changes: 10 additions & 0 deletions src/components/formFields/select/select.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

--conduction-input-select-placeholder-font-family: "Noto Sans", Arial, sans-serif;
--conduction-input-select-placeholder-color: #757575;

--conduction-input-select-group-font-size: 12px;
--conduction-input-select-group-text-color: grey;
--conduction-input-select-group-font-family: "Noto Sans", Arial, sans-serif;
}

.select > div {
Expand Down Expand Up @@ -56,3 +60,9 @@
border: var(--conduction-input-select-border-focus);
border-radius: var(--conduction-input-select-border-radius);
}

.groupLabel {
font-size: var(--conduction-input-select-group-font-size);
color: var(--conduction-input-select-group-text-color);
font-family: var(--conduction-input-select-group-font-family);
}
16 changes: 14 additions & 2 deletions src/components/formFields/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import * as React from "react";
import * as styles from "./select.module.css";
import clsx from "clsx";
import CreatableSelect from "react-select/creatable";
import ReactSelect, { MenuPlacement, StylesConfig } from "react-select";
import ReactSelect, { MenuPlacement, StylesConfig, GroupBase } from "react-select";
import { Control, Controller, FieldValues } from "react-hook-form";
import { IReactHookFormProps } from "../types";
import { ErrorMessage } from "../errorMessage/ErrorMessage";

export type TSelectOption = { label: string; value: string };
export type TGroupedSelectOption = { label: string; options: TSelectOption[] };

interface ISelectProps {
control: Control<FieldValues, any>;
options: { label: string; value: string }[];
options: TSelectOption[] | TGroupedSelectOption[];
name: string;
ariaLabel: string;
id?: string;
Expand Down Expand Up @@ -103,6 +106,7 @@ export const SelectMultiple = ({
menuPlacement={menuPlacement}
styles={selectStyles}
placeholder={disabled ? "Disabled..." : placeholder ?? "Select one or more options..."}
formatGroupLabel={(group) => <GroupLabel {...{ group }} />}
/>
{errors[name] && !hideErrorMessage && <ErrorMessage message={errors[name]?.message as string} />}
</>
Expand Down Expand Up @@ -148,6 +152,7 @@ export const SelectCreate = ({
menuPortalTarget={document.body}
menuPlacement={menuPlacement}
styles={selectStyles}
formatGroupLabel={(group) => <GroupLabel {...{ group }} />}
/>
{errors[name] && !hideErrorMessage && <ErrorMessage message={errors[name]?.message as string} />}
</>
Expand Down Expand Up @@ -193,6 +198,7 @@ export const SelectSingle = ({
menuPlacement={menuPlacement}
styles={selectStyles}
placeholder={disabled ? "Disabled..." : placeholder ?? "Select one or more options..."}
formatGroupLabel={(group) => <GroupLabel {...{ group }} />}
/>
{errors[name] && !hideErrorMessage && <ErrorMessage message={errors[name]?.message as string} />}
</>
Expand All @@ -201,3 +207,9 @@ export const SelectSingle = ({
/>
);
};

const GroupLabel: React.FC<{ group: GroupBase<unknown> }> = ({ group }) => {
if (!group.label) return <></>;

return <span className={styles.groupLabel}>{group.label}</span>;
};
21 changes: 5 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"declaration": true,
"outDir": "./lib",
"target": "esnext",
"lib": [
"dom",
"esnext"
],
"lib": ["dom", "esnext"],
"jsx": "react-jsx",
"module": "esnext",
"moduleResolution": "node",
Expand All @@ -15,15 +12,7 @@
"strict": true,
"skipLibCheck": true
},
"hooks": [
"copy-files"
],
"include": [
"src",
"src/**/*.css"
],
"exclude": [
"node_modules",
"**/__tests__/*"
]
}
"hooks": ["copy-files"],
"include": ["src", "src/**/*.css"],
"exclude": ["**/__tests__/*"]
}