From ce112c1b5f585fb0bd6ca9c364a602e677a7fe4f Mon Sep 17 00:00:00 2001 From: Kerry Date: Mon, 4 Dec 2023 08:30:07 +1300 Subject: [PATCH 1/2] Button refactor: use shared functional component for IconButton and Button (#133) * use shared internal button for Button and IconButton * comment * update disabled styles and tests for IconButton --- src/components/Alert/Alert.tsx | 2 +- .../Alert/__snapshots__/Alert.test.tsx.snap | 12 +- src/components/Button/Button.tsx | 35 +--- .../IconButton/IconButton.module.css | 10 +- .../IconButton/IconButton.stories.tsx | 44 +++-- .../Button/IconButton/IconButton.test.tsx | 53 ++++++ .../{ => Button}/IconButton/IconButton.tsx | 38 ++-- .../__snapshots__/IconButton.test.tsx.snap | 174 ++++++++++++++++++ .../IconButton/indicator-mask.svg | 0 src/components/Button/UnstyledButton.tsx | 89 +++++++++ .../IconButton.test.tsx => Button/index.ts} | 22 +-- .../__snapshots__/IconButton.test.tsx.snap | 32 ---- src/components/Tooltip/Tooltip.stories.tsx | 2 +- src/components/Tooltip/Tooltip.test.tsx | 2 +- .../__snapshots__/Tooltip.test.tsx.snap | 8 +- src/index.ts | 3 +- 16 files changed, 404 insertions(+), 122 deletions(-) rename src/components/{ => Button}/IconButton/IconButton.module.css (89%) rename src/components/{ => Button}/IconButton/IconButton.stories.tsx (67%) create mode 100644 src/components/Button/IconButton/IconButton.test.tsx rename src/components/{ => Button}/IconButton/IconButton.tsx (69%) create mode 100644 src/components/Button/IconButton/__snapshots__/IconButton.test.tsx.snap rename src/components/{ => Button}/IconButton/indicator-mask.svg (100%) create mode 100644 src/components/Button/UnstyledButton.tsx rename src/components/{IconButton/IconButton.test.tsx => Button/index.ts} (51%) delete mode 100644 src/components/IconButton/__snapshots__/IconButton.test.tsx.snap diff --git a/src/components/Alert/Alert.tsx b/src/components/Alert/Alert.tsx index 39261532..6ce5b008 100644 --- a/src/components/Alert/Alert.tsx +++ b/src/components/Alert/Alert.tsx @@ -24,7 +24,7 @@ import CloseIcon from "@vector-im/compound-design-tokens/icons/close.svg"; import styles from "./Alert.module.css"; import { Text } from "../Typography/Text"; -import { IconButton } from "../IconButton/IconButton"; +import { IconButton } from "../Button"; type AlertProps = { /** diff --git a/src/components/Alert/__snapshots__/Alert.test.tsx.snap b/src/components/Alert/__snapshots__/Alert.test.tsx.snap index 863dc3a1..d6c3e50e 100644 --- a/src/components/Alert/__snapshots__/Alert.test.tsx.snap +++ b/src/components/Alert/__snapshots__/Alert.test.tsx.snap @@ -72,9 +72,10 @@ exports[`Alert > renders actions 1`] = ` + +`; + +exports[`IconButton > renders a DefaultDisabled IconButton 1`] = ` +
+ +
+`; + +exports[`IconButton > renders a WithHighlightIndicator IconButton 1`] = ` +
+ +
+`; + +exports[`IconButton > renders a WithIndicator IconButton 1`] = ` +
+ +
+`; + +exports[`IconButton > renders a WithIndicatorDisabled IconButton 1`] = ` +
+ +
+`; diff --git a/src/components/IconButton/indicator-mask.svg b/src/components/Button/IconButton/indicator-mask.svg similarity index 100% rename from src/components/IconButton/indicator-mask.svg rename to src/components/Button/IconButton/indicator-mask.svg diff --git a/src/components/Button/UnstyledButton.tsx b/src/components/Button/UnstyledButton.tsx new file mode 100644 index 00000000..bce30306 --- /dev/null +++ b/src/components/Button/UnstyledButton.tsx @@ -0,0 +1,89 @@ +/* +Copyright 2023 New Vector Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React, { PropsWithChildren, forwardRef, ForwardedRef, Ref } from "react"; + +interface ButtonComponent { + // With the explicit `as` prop + ( + props: { as: C } & UnstyledButtonPropsFor, + ): React.ReactElement; + // Without the explicit `as` prop, defaulting to a - -`; diff --git a/src/components/Tooltip/Tooltip.stories.tsx b/src/components/Tooltip/Tooltip.stories.tsx index 320b20f4..d882278d 100644 --- a/src/components/Tooltip/Tooltip.stories.tsx +++ b/src/components/Tooltip/Tooltip.stories.tsx @@ -18,7 +18,7 @@ import React from "react"; import { Meta, StoryFn } from "@storybook/react"; import { Tooltip as TooltipComponent } from "./Tooltip"; -import { IconButton } from "../IconButton/IconButton"; +import { IconButton } from "../Button"; import UserIcon from "@vector-im/compound-design-tokens/icons/user-profile.svg"; diff --git a/src/components/Tooltip/Tooltip.test.tsx b/src/components/Tooltip/Tooltip.test.tsx index 8b460644..42c9384f 100644 --- a/src/components/Tooltip/Tooltip.test.tsx +++ b/src/components/Tooltip/Tooltip.test.tsx @@ -19,7 +19,7 @@ import { render } from "@testing-library/react"; import React from "react"; import { Tooltip } from "./Tooltip"; -import { IconButton } from "../IconButton/IconButton"; +import { IconButton } from "../Button"; describe("Tooltip", () => { beforeAll(() => { diff --git a/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap b/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap index 2369ce34..7a42e8b2 100644 --- a/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap +++ b/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap @@ -3,9 +3,11 @@ exports[`Tooltip > renders 1`] = ` @@ -16,9 +18,11 @@ exports[`Tooltip > renders open by default 1`] = ` diff --git a/src/index.ts b/src/index.ts index 239e00d8..25be450b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ export { Alert } from "./components/Alert/Alert"; export { Avatar } from "./components/Avatar/Avatar"; export { AvatarStack } from "./components/Avatar/AvatarStack"; export { Badge } from "./components/Badge/Badge"; -export { Button } from "./components/Button/Button"; +export { Button, IconButton } from "./components/Button"; export { Body } from "./components/Typography/Body"; export { Text } from "./components/Typography/Text"; export { Glass } from "./components/Glass/Glass"; @@ -35,7 +35,6 @@ export { H5, H6, } from "./components/Typography/Heading"; -export { IconButton } from "./components/IconButton/IconButton"; export { Link } from "./components/Link/Link"; export { Menu } from "./components/Menu/Menu"; export { MenuItem } from "./components/Menu/MenuItem"; From 964280ee2a29fbeef5e6a11d887388c878925a01 Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Sun, 3 Dec 2023 19:34:15 +0000 Subject: [PATCH 2/2] patch version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3aabae7..f7579b8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vector-im/compound-web", - "version": "0.9.1", + "version": "0.9.2", "description": "Compound components for the Web", "type": "module", "main": "./dist/compound-web.js",