Skip to content

Commit

Permalink
feat: [M3-8177] - Add MultipleIPInput Story (#11389)
Browse files Browse the repository at this point in the history
* feat: [M3-8177] - Add MultipleIPInput Story

* Added changeset: MultipleIPInput Story in Storybook

* Add functionality to `HelperText` and `Placeholder`

* Add functionality to `Placeholder`
  • Loading branch information
hasyed-akamai authored Dec 18, 2024
1 parent 5469160 commit 8ff2562
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11389-added-1733834884159.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

MultipleIPInput Story in Storybook ([#11389](https://github.com/linode/manager/pull/11389))
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { useState } from 'react';

import { MultipleIPInput } from './MultipleIPInput';

import type { MultipeIPInputProps } from './MultipleIPInput';
import type { Meta, StoryFn, StoryObj } from '@storybook/react';

type Story = StoryObj<typeof MultipleIPInput>;

const mockTitle = 'IP Address';

const defaultArgs = {
buttonText: 'Add An IP',
ips: [{ address: '192.0.2.1/01' }, { address: '192.0.2.1/02' }],
title: mockTitle,
};

const meta: Meta<typeof MultipleIPInput> = {
component: MultipleIPInput,
decorators: [
(Story: StoryFn) => (
<div style={{ margin: '2em' }}>
<Story />
</div>
),
],
title: 'Components/MultipleIPInput',
};

export default meta;

const MultipleIPInputWithState = ({ ...args }: MultipeIPInputProps) => {
const [ips, setIps] = useState(args.ips);

const handleChange = (newIps: typeof ips) => {
setIps(newIps);
};

return <MultipleIPInput {...args} ips={ips} onChange={handleChange} />;
};

export const Default: Story = {
args: defaultArgs,
render: (args) => {
return <MultipleIPInputWithState {...args} />;
},
};

export const Disabled: Story = {
args: {
...defaultArgs,
disabled: true,
},
};

export const HelperText: Story = {
args: {
...defaultArgs,
helperText: 'helperText',
},
render: (args) => {
return <MultipleIPInputWithState {...args} />;
},
};

export const Placeholder: Story = {
args: {
ips: [{ address: '' }],
placeholder: 'placeholder',
title: mockTitle,
},
render: (args) => {
return <MultipleIPInputWithState {...args} />;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,89 @@ const useStyles = makeStyles()((theme: Theme) => ({
}));

export interface MultipeIPInputProps {
/**
* Text displayed on the button.
*/
buttonText?: string;

/**
* Custom CSS class for additional styling.
*/
className?: string;

/**
* Disables the component (non-interactive).
* @default false
*/
disabled?: boolean;

/**
* Error message for invalid input.
*/
error?: string;

/**
* Indicates if the input relates to database access controls.
* @default false
*/
forDatabaseAccessControls?: boolean;

/**
* Indicates if the input is for VPC IPv4 ranges.
* @default false
*/
forVPCIPv4Ranges?: boolean;

/**
* Helper text for additional guidance.
*/
helperText?: string;

/**
* Custom input properties passed to the underlying input component.
*/
inputProps?: InputBaseProps;

/**
* Array of `ExtendedIP` objects representing managed IPs.
*/
ips: ExtendedIP[];

/**
* Styles the button as a link.
* @default false
*/
isLinkStyled?: boolean;

/**
* Callback triggered when the input loses focus, passing updated `ips`.
*/
onBlur?: (ips: ExtendedIP[]) => void;

/**
* Callback triggered when IPs change, passing updated `ips`.
*/
onChange: (ips: ExtendedIP[]) => void;

/**
* Placeholder text for an empty input field.
*/
placeholder?: string;

/**
* Indicates if the input is required for form submission.
* @default false
*/
required?: boolean;

/**
* Title or label for the input field.
*/
title: string;

/**
* Tooltip text for extra info on hover.
*/
tooltip?: string;
}

Expand Down

0 comments on commit 8ff2562

Please sign in to comment.