diff --git a/src/components/button/button.jsx b/src/components/button/button.jsx index 160db04b..3eee32d7 100644 --- a/src/components/button/button.jsx +++ b/src/components/button/button.jsx @@ -1,7 +1,7 @@ -import React from 'react'; +import React, { forwardRef } from 'react'; import { cn } from '@/utilities/functions'; -const Button = ( props ) => { +const Button = forwardRef( ( props, ref ) => { const { variant = 'primary', // primary, secondary, outline, ghost, link size = 'md', // xs, sm, md, lg @@ -67,6 +67,7 @@ const Button = ( props ) => { const Tag = tag; return ( { { iconRight } ); -}; +} ); export default Button; diff --git a/src/components/label/label.jsx b/src/components/label/label.jsx index 3bbea087..707ee5e9 100644 --- a/src/components/label/label.jsx +++ b/src/components/label/label.jsx @@ -1,10 +1,11 @@ import { cn } from '@/utilities/functions'; +import React, { forwardRef } from 'react'; /** * Label component. */ -const Label = ( { +const Label = forwardRef( ( { children = null, tag = 'label', size = 'sm', // xs, sm, md @@ -12,7 +13,7 @@ const Label = ( { variant = 'neutral', // neutral, help, error, disabled required = false, ...props -} ) => { +}, ref ) => { // Base classes. - Mandatory classes. const baseClasses = 'font-medium text-field-label flex items-center gap-0.5'; @@ -48,6 +49,7 @@ const Label = ( { return ( ); -}; +} ); export default Label; diff --git a/src/components/tooltip/readme.md b/src/components/tooltip/readme.md index 2f0cee19..1cb3c66c 100644 --- a/src/components/tooltip/readme.md +++ b/src/components/tooltip/readme.md @@ -8,14 +8,14 @@ The `Tooltips` are small, interactive pop-up boxes that provide brief, informati ### `variant` - **Type:** `string` -- **Default:** `"light"` +- **Default:** `"dark"` - **Description:** Defines the style variant of the tooltip. Options include: - `"light"` - `"dark"` ### `placement` - **Type:** `string` -- **Default:** `"top"` +- **Default:** `"bottom"` - **Description:** Defines the position of the tooltip. Options include: - `"top"` - `"top-start"` diff --git a/src/components/tooltip/tooltip.stories.js b/src/components/tooltip/tooltip.stories.js new file mode 100644 index 00000000..ed84d42d --- /dev/null +++ b/src/components/tooltip/tooltip.stories.js @@ -0,0 +1,176 @@ +import React, { useState } from 'react'; +import Tooltip from './tooltip.jsx'; +import { CircleHelp } from 'lucide-react'; +import Label from '../label/label.jsx'; + +export default { + title: 'Molecules/Tooltip', + component: Tooltip, + parameters: { + layout: 'centered', + }, + tags: [ 'autodocs' ], + argTypes: { + variant: { + description: 'Defines the style variant of the tooltip.', + control: { type: 'select' }, + options: [ 'light', 'dark' ], + table: { + type: { summary: 'string' }, + }, + }, + placement: { + description: 'The placement of the tooltip relative to the target.', + control: { type: 'select' }, + options: [ + 'top', 'top-start', 'top-end', + 'bottom', 'bottom-start', 'bottom-end', + 'right', 'right-start', 'right-end', + 'left', 'left-start', 'left-end', + ], + table: { + type: { summary: 'string' }, + }, + }, + title: { + description: 'Title for the tooltip.', + control: { type: 'text' }, + table: { + type: { summary: 'string' }, + }, + }, + content: { + description: 'Content of tooltip - description of tooltip in more detail.', + control: { type: 'text' }, + table: { + type: { summary: 'string' }, + }, + }, + arrow: { + description: 'Defines whether the tooltip is displayed with an arrow or not.', + control: { type: 'boolean' }, + table: { + type: { summary: 'boolean' }, + }, + }, + open: { + description: 'Controls the open state when controlled mode is used.', + control: { type: 'boolean' }, + table: { + type: { summary: 'boolean' }, + }, + }, + triggers: { + description: 'Triggers to open the tooltip (hover, focus, click).', + control: { type: 'select' }, + options: [ 'click', 'hover', 'focus' ], + table: { + type: { summary: 'string' }, + }, + }, + interactive: { + description: 'If set to true, the tooltip is interactive and will not close when the user hovers over the tooltip.', + control: { type: 'boolean' }, + table: { + type: { summary: 'boolean' }, + }, + }, + offset: { + description: 'Defines the offset of the tooltip from the target element.', + control: { type: 'number' }, + table: { + type: { summary: 'number' }, + }, + }, + tooltipPortalRoot: { + description: "Root element where the tooltip will be rendered. It's helpful when the tooltip is rendered outside the parent container and scopped Tailwind CSS styles.", + table: { + type: { summary: 'HTMLElement | null' }, + }, + }, + tooltipPortalId: { + description: "Root element where the tooltip will be rendered. It's helpful when the tooltip is rendered outside the parent container and scopped Tailwind CSS styles.", + table: { + type: { summary: 'HTMLElement | null' }, + }, + }, + boundary: { + description: 'The element that the tooltip is positioned relative to. When provided, the tooltip will be positioned within the boundary of the element.', + table: { + type: { summary: 'HTMLElement' }, + }, + }, + strategy: { + description: 'Defines the positioning strategy of the tooltip. Options include: `absolute` and `fixed`. The `fixed` strategy is recommended for most use cases.', + table: { + type: { summary: 'string' }, + }, + }, + }, +}; + +export const DefaultTooltip = ( args ) => { + const [ isOpen, setIsOpen ] = useState( false ); + + return ( +
+ + + +
+ ); +}; + +DefaultTooltip.args = { + variant: 'dark', + placement: 'bottom', + title: 'Tooltip Title', + content: 'This is the content of the tooltip.', + arrow: true, + triggers: [ 'hover', 'focus' ], + interactive: false, +}; + +export const DarkTooltipWithIcon = ( args ) => ( +
+ { [ 'top-end', 'top', 'top-start', 'left', 'bottom', 'right' ].map( ( placement ) => ( +
+ + + +
+ ) ) } +
+); + +DarkTooltipWithIcon.storyName = 'Tooltip with icon'; + +DarkTooltipWithIcon.args = { + variant: 'dark', + title: 'Tooltip', + arrow: true, +}; + +export const DarkTooltipWithLabel = ( args ) => ( +
+ { [ 'top-end', 'top', 'top-start', 'left', 'bottom', 'right' ].map( ( placement ) => ( +
+ + + +
+ ) ) } +
+); + +DarkTooltipWithLabel.storyName = 'Tooltip with label'; + +DarkTooltipWithLabel.args = { + variant: 'dark', + title: 'Tooltip', + arrow: true, +};