diff --git a/app/components/IconPicker/index.tsx b/app/components/IconPicker/index.tsx index 00459e5c40..036424a56d 100644 --- a/app/components/IconPicker/index.tsx +++ b/app/components/IconPicker/index.tsx @@ -2,7 +2,7 @@ import * as Tabs from "@radix-ui/react-tabs"; import { SmileyIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; -import styled, { css } from "styled-components"; +import styled from "styled-components"; import Icon from "@shared/components/Icon"; import { s, hover } from "@shared/styles"; import theme from "@shared/styles/theme"; @@ -15,6 +15,7 @@ import { PopoverTrigger, PopoverContent, } from "~/components/primitives/Popover"; +import { Tab, TabsGroup } from "~/components/Tabs"; import useMobile from "~/hooks/useMobile"; import useWindowSize from "~/hooks/useWindowSize"; import { Drawer, DrawerContent, DrawerTrigger } from "../primitives/Drawer"; @@ -238,22 +239,26 @@ const Content = ({ return ( - - - {t("Icons")} - - - {t("Emojis")} - - + + + + + {t("Icons")} + + + + + {t("Emojis")} + + + + {allowDelete && ( {t("Remove")} )} @@ -308,35 +313,9 @@ const TabActionsWrapper = styled(Flex)` border-bottom: 1px solid ${s("inputBorder")}; `; -const StyledTab = styled(Tabs.Trigger)<{ $active: boolean }>` - position: relative; - font-weight: 500; - font-size: 14px; - cursor: var(--pointer); - background: none; - border: 0; - padding: 8px 12px; - user-select: none; - color: ${({ $active }) => ($active ? s("textSecondary") : s("textTertiary"))}; - transition: color 100ms ease-in-out; - - &: ${hover} { - color: ${s("textSecondary")}; - } - - ${({ $active }) => - $active && - css` - &:after { - content: ""; - position: absolute; - bottom: 0; - left: 0; - right: 0; - height: 1px; - background: ${s("textSecondary")}; - } - `} +const TabsList = styled(Tabs.List)` + display: flex; + gap: 24px; `; const StyledTabContent = styled(Tabs.Content)` diff --git a/app/components/Tabs/Tab.tsx b/app/components/Tabs/Tab.tsx index 71a4f61115..381fc8ec0e 100644 --- a/app/components/Tabs/Tab.tsx +++ b/app/components/Tabs/Tab.tsx @@ -33,11 +33,12 @@ interface LinkProps extends BaseProps { active?: never; } -interface ButtonProps extends BaseProps { +interface ButtonProps + extends BaseProps, React.ButtonHTMLAttributes { /** - * Click handler for button mode. + * Click handler for button mode, optional when the parent handles selection. */ - onClick: () => void; + onClick?: React.MouseEventHandler; /** * Whether the tab is currently active (only used in button mode). */ @@ -106,7 +107,15 @@ const horizontalOnly = (transform: Record, generated: string) => "translate3d($1, 0px, $2)" ); -export const Tab: React.FC = (props: Props) => { +/** + * A single tab with an animated active underline, rendered either as a link + * matched against the current location, or as a button in controlled mode. + * A forwarded ref is only attached in button mode. + */ +export const Tab = React.forwardRef(function Tab( + props: Props, + ref +) { const { children, exact, exactQueryString } = props; const theme = useTheme(); const activeStyle = { @@ -115,10 +124,17 @@ export const Tab: React.FC = (props: Props) => { // Button mode - controlled by onClick and active props (no `to` prop) if ("active" in props && !("to" in props)) { + const { + active, + exact: _exact, + exactQueryString: _exactQueryString, + ...rest + } = props; + return ( - + {children} - {props.active && ( + {active && ( = (props: Props) => { )} ); -}; +}); diff --git a/app/components/Tabs/Tabs.tsx b/app/components/Tabs/Tabs.tsx index e28333faa5..69877ef130 100644 --- a/app/components/Tabs/Tabs.tsx +++ b/app/components/Tabs/Tabs.tsx @@ -64,13 +64,20 @@ type Props = { children?: React.ReactNode; }; +/** + * Namespaces the shared layout animation of the tabs it contains, so that + * multiple tab bars on screen at once don't share the "underline" layoutId and + * animate between each other. Only needed when composing `Tab` outside of `Tabs`. + */ +export const TabsGroup: React.FC = ({ children }: Props) => { + const layoutGroupId = React.useMemo(() => uniqueId("tabs-"), []); + return {children}; +}; + export const Tabs: React.FC = ({ children }: Props) => { const ref = React.useRef(null); const [shadowVisible, setShadow] = React.useState(false); const { width } = useWindowSize(); - // Namespace the shared layout animation so multiple tab bars on screen at - // once don't share the "underline" layoutId and animate between each other. - const layoutGroupId = React.useMemo(() => uniqueId("tabs-"), []); const updateShadows = React.useCallback(() => { const c = ref.current; @@ -91,12 +98,12 @@ export const Tabs: React.FC = ({ children }: Props) => { }, [width, updateShadows]); return ( - + - + ); }; diff --git a/app/components/Tabs/index.ts b/app/components/Tabs/index.ts index 8709a5e5ab..0830f70744 100644 --- a/app/components/Tabs/index.ts +++ b/app/components/Tabs/index.ts @@ -1,2 +1,2 @@ export { Tab } from "./Tab"; -export { Separator, Tabs } from "./Tabs"; +export { Separator, Tabs, TabsGroup } from "./Tabs";