import React from 'react'; import styled from 'styled-components'; import { useMutation } from 'react-query'; import { InlineInput } from '../../src/lib'; import { Button } from '../../src/lib/components/buttonv2/Buttonv2.component'; import { Modal } from '../../src/lib/components/modal/Modal.component'; import { Stack, spacing } from '../../src/lib/spacing'; const InfoLabel = styled.span` display: inline-block; min-width: 10.714rem; color: ${(props) => props.theme.textSecondary}; `; const InfoRow = styled.div` padding-bottom: ${spacing.r20}; padding-left: ${spacing.r20}; display: flex; align-items: center; `; const InfoValue = styled.span` color: ${(props) => props.theme.textPrimary}; padding-left: 0.313rem; `; const LabelValueLayout = ({ children }: { children: React.ReactNode }) => (
Node ID node-abc-123 Display Name {children} Name node-name-2 Control Plane IP 10.0.0.12 Roles worker
); const useFakeMutation = ({ delay = 1500 }: { delay?: number } = {}) => useMutation({ mutationFn: ({ value }) => { return new Promise((resolve) => { setTimeout(() => resolve(value), delay); }); }, }); const useFailingMutation = () => useMutation({ mutationFn: () => { return new Promise((_, reject) => { setTimeout(() => reject(new Error('Something went wrong')), 800); }); }, }); export default { title: 'Components/InlineInput', component: InlineInput, args: { id: 'instanceName', defaultValue: 'My instance', }, argTypes: { changeMutation: { table: { disable: true } }, confirmationModal: { table: { disable: true } }, check: { table: { disable: true } }, }, decorators: [ (Story: React.ComponentType) => ( ), ], }; export const Default = { render: (args: React.ComponentProps) => { const changeMutation = useFakeMutation(); return ; }, }; export const Editing = { render: (args: React.ComponentProps) => { const changeMutation = useFakeMutation(); return ; }, play: async ({ canvasElement }: { canvasElement: HTMLElement }) => { const trigger = canvasElement.querySelector( '[role="button"][aria-label="Edit"]', ); trigger?.click(); }, }; export const WithValidation = { render: (args: React.ComponentProps) => { const changeMutation = useFakeMutation(); return ( { if (value.trim().length < 3) { return { hasError: true, message: 'Name must be at least 3 characters', }; } if (!/^[a-zA-Z0-9-]+$/.test(value.trim())) { return { hasError: true, message: 'Only letters, digits and dashes are allowed', }; } return { hasError: false }; }} /> ); }, }; export const WithFloatingError = { render: (args: React.ComponentProps) => { const changeMutation = useFakeMutation(); return ( { if (value.trim().length < 3) { return { hasError: true, message: 'Name must be at least 3 characters', }; } if (!/^[a-zA-Z0-9-]+$/.test(value.trim())) { return { hasError: true, message: 'Only letters, digits and dashes are allowed', }; } return { hasError: false }; }} /> ); }, }; export const Loading = { render: (args: React.ComponentProps) => { // Force a long-running mutation that's pre-triggered when the story mounts. const changeMutation = useFakeMutation({ delay: 60_000 }); React.useEffect(() => { changeMutation.mutate({ value: 'My instance' }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ; }, }; export const WithConfirmationModal = { render: (args: React.ComponentProps) => { const changeMutation = useFakeMutation(); return ( (