Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agility/plenum-ui",
"version": "2.3.3",
"version": "2.3.4",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
19 changes: 19 additions & 0 deletions stories/molecules/inputs/select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import Select from "./Select";

const meta: Meta<typeof Select> = {
Expand Down Expand Up @@ -90,6 +91,24 @@ export const ManyOptions: TStory = {
}
};

export const WithLabelAction: TStory = {
args: {
label: "Batch",
id: "select-label-action",
name: "select-label-action",
isRequired: true,
options: [
{ label: "Batch 1", value: "batch-1" },
{ label: "Batch 2", value: "batch-2" },
{ label: "Batch 3", value: "batch-3" }
],
labelAction: {
label: "Add new batch",
onClick: action("labelAction clicked")
}
}
};

export const DefaultSelectDarkBG: TStory = {
args: {
label: "Label",
Expand Down
34 changes: 31 additions & 3 deletions stories/molecules/inputs/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ComboboxOption
} from "@headlessui/react";
import { Paragraph } from "@/stories/atoms/Typography/Paragraph";
import { Label } from "@/stories/atoms/Typography/Label";

export interface ISimpleSelectOptions {
label: string;
Expand All @@ -20,6 +21,12 @@ export interface ISimpleSelectOptions {
caption?: string;
}

interface LabelAction {
label: string;
onClick: () => void;
className?: string;
}

export interface ISelectProps {
/** Label */
label?: string;
Expand All @@ -46,6 +53,7 @@ export interface ISelectProps {
placeholder?: string;
dropdownMaxHeight?: number;
dropdownMaxWidth?: number;
labelAction?: LabelAction;
}

const Select: React.FC<ISelectProps> = ({
Expand All @@ -65,7 +73,8 @@ const Select: React.FC<ISelectProps> = ({
inputRef,
placeholder = "Select",
dropdownMaxHeight = 240,
dropdownMaxWidth = 240
dropdownMaxWidth = 240,
labelAction
}) => {
const uniqueID = useId();
if (!id) id = `select-${uniqueID}`;
Expand Down Expand Up @@ -101,7 +110,25 @@ const Select: React.FC<ISelectProps> = ({

return (
<div className={wrapperStyle}>
{label && <InputLabel id={`${id}-label`} label={label} isRequired={isRequired} />}
{(label || labelAction) && (
<div className="flex items-center justify-between">
{label && (
<InputLabel
id={`${id}-label`}
label={label}
isRequired={isRequired}
noMarginBottom={!!labelAction}
/>
)}
{labelAction && (
<button type="button" onClick={labelAction.onClick}>
<Label size="sm" className={cn("text-primary-700", labelAction.className)}>
{labelAction.label}
</Label>
</button>
)}
</div>
)}

<HeadlessCombobox value={selectedOption} onChange={handleChange} disabled={isDisabled} immediate by="value">
<div ref={containerRef} className="relative w-full">
Expand Down Expand Up @@ -177,7 +204,8 @@ const Select: React.FC<ISelectProps> = ({
title={option.label}
onMouseEnter={(e) => {
const el = e.currentTarget;
if (el.scrollWidth <= el.clientWidth) el.removeAttribute("title");
if (el.scrollWidth <= el.clientWidth)
el.removeAttribute("title");
}}
onMouseLeave={(e) => {
e.currentTarget.setAttribute("title", option.label);
Expand Down
Loading