From 8be3295bfbc88218f5b4ac2234ae0049a57ce311 Mon Sep 17 00:00:00 2001 From: DerekAgility Date: Wed, 13 May 2026 14:26:20 -0400 Subject: [PATCH] Added label action for select --- package.json | 2 +- .../inputs/select/Select.stories.tsx | 19 +++++++++++ stories/molecules/inputs/select/Select.tsx | 34 +++++++++++++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 03cbbfc..67bc981 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/stories/molecules/inputs/select/Select.stories.tsx b/stories/molecules/inputs/select/Select.stories.tsx index 45f4d45..360f97f 100644 --- a/stories/molecules/inputs/select/Select.stories.tsx +++ b/stories/molecules/inputs/select/Select.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react"; +import { action } from "@storybook/addon-actions"; import Select from "./Select"; const meta: Meta = { @@ -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", diff --git a/stories/molecules/inputs/select/Select.tsx b/stories/molecules/inputs/select/Select.tsx index 565a55d..7b69f01 100644 --- a/stories/molecules/inputs/select/Select.tsx +++ b/stories/molecules/inputs/select/Select.tsx @@ -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; @@ -20,6 +21,12 @@ export interface ISimpleSelectOptions { caption?: string; } +interface LabelAction { + label: string; + onClick: () => void; + className?: string; +} + export interface ISelectProps { /** Label */ label?: string; @@ -46,6 +53,7 @@ export interface ISelectProps { placeholder?: string; dropdownMaxHeight?: number; dropdownMaxWidth?: number; + labelAction?: LabelAction; } const Select: React.FC = ({ @@ -65,7 +73,8 @@ const Select: React.FC = ({ inputRef, placeholder = "Select", dropdownMaxHeight = 240, - dropdownMaxWidth = 240 + dropdownMaxWidth = 240, + labelAction }) => { const uniqueID = useId(); if (!id) id = `select-${uniqueID}`; @@ -101,7 +110,25 @@ const Select: React.FC = ({ return (
- {label && } + {(label || labelAction) && ( +
+ {label && ( + + )} + {labelAction && ( + + )} +
+ )}
@@ -177,7 +204,8 @@ const Select: React.FC = ({ 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);