diff --git a/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.story.tsx b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.story.tsx new file mode 100644 index 0000000000000..bc896fb67365e --- /dev/null +++ b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.story.tsx @@ -0,0 +1,50 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React, { useState } from 'react'; + +import { ButtonTextWithAddIcon } from './ButtonTextWithAddIcon'; + +export default { + title: 'Shared', +}; + +export const Button = () => { + const [label, setLabel] = useState('Add Item (click me)'); + return ( +
+ null} /> + setLabel('Add More Item (click me)')} + /> + null} + disabled={true} + /> + null} + iconSize={'medium'} + /> +
+ ); +}; + +Button.storyName = 'ButtonTextWithAddIcon'; diff --git a/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.test.tsx b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.test.tsx new file mode 100644 index 0000000000000..6d88f3c1d26b5 --- /dev/null +++ b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.test.tsx @@ -0,0 +1,46 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React from 'react'; + +import { render, fireEvent, screen } from 'design/utils/testing'; + +import { ButtonTextWithAddIcon } from './ButtonTextWithAddIcon'; + +test('buttonTextWithAddIcon', () => { + const onClick = jest.fn(); + const label = 'Add Item'; + + const { rerender } = render( + onClick('click')} /> + ); + + expect(screen.getByText('Add Item')).toBeInTheDocument(); + fireEvent.click(screen.getByText('Add Item')); + + expect(onClick).toHaveBeenCalledWith('click'); + + rerender( + onClick('click')} + disabled={true} + /> + ); + expect(screen.getByText('Add Item')).toBeDisabled(); +}); diff --git a/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.tsx b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.tsx new file mode 100644 index 0000000000000..b8e0ac49c0143 --- /dev/null +++ b/web/packages/shared/components/ButtonTextWithAddIcon/ButtonTextWithAddIcon.tsx @@ -0,0 +1,58 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React from 'react'; +import { ButtonText } from 'design'; +import { Add as AddIcon } from 'design/Icon'; + +export const ButtonTextWithAddIcon = ({ + label, + onClick, + disabled, + iconSize = 12, +}: { + label: string; + onClick: () => void; + disabled?: boolean; + iconSize?: number | 'small' | 'medium' | 'large' | 'extraLarge'; +}) => { + return ( + + + {label} + + ); +}; diff --git a/web/packages/shared/components/ButtonTextWithAddIcon/index.ts b/web/packages/shared/components/ButtonTextWithAddIcon/index.ts new file mode 100644 index 0000000000000..9493670ce549b --- /dev/null +++ b/web/packages/shared/components/ButtonTextWithAddIcon/index.ts @@ -0,0 +1,19 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export { ButtonTextWithAddIcon } from './ButtonTextWithAddIcon'; diff --git a/web/packages/teleport/src/Discover/Shared/LabelsCreater/LabelsCreater.tsx b/web/packages/teleport/src/Discover/Shared/LabelsCreater/LabelsCreater.tsx index e31e80bf769f4..399c346438ce3 100644 --- a/web/packages/teleport/src/Discover/Shared/LabelsCreater/LabelsCreater.tsx +++ b/web/packages/teleport/src/Discover/Shared/LabelsCreater/LabelsCreater.tsx @@ -17,11 +17,12 @@ */ import React from 'react'; -import { Box, Flex, ButtonIcon, ButtonText, Text } from 'design'; +import { Box, Flex, ButtonIcon, Text } from 'design'; import * as Icons from 'design/Icon'; import FieldInput from 'shared/components/FieldInput'; import { useValidation, Validator } from 'shared/components/Validation'; import { requiredField } from 'shared/components/Validation/rules'; +import { ButtonTextWithAddIcon } from 'shared/components/ButtonTextWithAddIcon'; import { ResourceLabel } from 'teleport/services/agents'; @@ -174,30 +175,12 @@ export function LabelsCreater({ ); })} - - - Add New Label - + iconSize="small" + /> ); }