mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
Replace custom tabs in IconPicker (#13358)
* Replace custom tabs in IconPicker * Use standard click handler type for Tab in button mode Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
689cec6cd4
commit
77fcd895c4
4 files changed
+61
-59
No files matched your search
@@ -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 (
|
||||
<Tabs.Root value={activeTab} onValueChange={onTabChange}>
|
||||
<TabActionsWrapper justify="space-between" align="center">
|
||||
<Tabs.List>
|
||||
<StyledTab
|
||||
value={TAB_NAMES["Icon"]}
|
||||
aria-label={t("Icons")}
|
||||
$active={activeTab === TAB_NAMES["Icon"]}
|
||||
>
|
||||
{t("Icons")}
|
||||
</StyledTab>
|
||||
<StyledTab
|
||||
value={TAB_NAMES["Emoji"]}
|
||||
aria-label={t("Emojis")}
|
||||
$active={activeTab === TAB_NAMES["Emoji"]}
|
||||
>
|
||||
{t("Emojis")}
|
||||
</StyledTab>
|
||||
</Tabs.List>
|
||||
<TabsGroup>
|
||||
<TabsList>
|
||||
<Tabs.Trigger value={TAB_NAMES["Icon"]} asChild>
|
||||
<Tab
|
||||
aria-label={t("Icons")}
|
||||
active={activeTab === TAB_NAMES["Icon"]}
|
||||
>
|
||||
{t("Icons")}
|
||||
</Tab>
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value={TAB_NAMES["Emoji"]} asChild>
|
||||
<Tab
|
||||
aria-label={t("Emojis")}
|
||||
active={activeTab === TAB_NAMES["Emoji"]}
|
||||
>
|
||||
{t("Emojis")}
|
||||
</Tab>
|
||||
</Tabs.Trigger>
|
||||
</TabsList>
|
||||
</TabsGroup>
|
||||
{allowDelete && (
|
||||
<RemoveButton onClick={onIconRemove}>{t("Remove")}</RemoveButton>
|
||||
)}
|
||||
@@ -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)`
|
||||
|
||||
@@ -33,11 +33,12 @@ interface LinkProps extends BaseProps {
|
||||
active?: never;
|
||||
}
|
||||
|
||||
interface ButtonProps extends BaseProps {
|
||||
interface ButtonProps
|
||||
extends BaseProps, React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
/**
|
||||
* Click handler for button mode.
|
||||
* Click handler for button mode, optional when the parent handles selection.
|
||||
*/
|
||||
onClick: () => void;
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
/**
|
||||
* Whether the tab is currently active (only used in button mode).
|
||||
*/
|
||||
@@ -106,7 +107,15 @@ const horizontalOnly = (transform: Record<string, string>, generated: string) =>
|
||||
"translate3d($1, 0px, $2)"
|
||||
);
|
||||
|
||||
export const Tab: React.FC<Props> = (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<HTMLButtonElement, Props>(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: 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 (
|
||||
<TabButton $active={props.active} onClick={props.onClick}>
|
||||
<TabButton {...rest} ref={ref} type="button" $active={active}>
|
||||
{children}
|
||||
{props.active && (
|
||||
{active && (
|
||||
<Active
|
||||
layoutId="underline"
|
||||
initial={false}
|
||||
@@ -159,4 +175,4 @@ export const Tab: React.FC<Props> = (props: Props) => {
|
||||
)}
|
||||
</TabLink>
|
||||
);
|
||||
};
|
||||
});
|
||||
@@ -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 <LayoutGroup id={layoutGroupId}>{children}</LayoutGroup>;
|
||||
};
|
||||
|
||||
export const Tabs: React.FC = ({ children }: Props) => {
|
||||
const ref = React.useRef<HTMLElement>(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 (
|
||||
<LayoutGroup id={layoutGroupId}>
|
||||
<TabsGroup>
|
||||
<Sticky>
|
||||
<Nav ref={ref} onScroll={updateShadows} $shadowVisible={shadowVisible}>
|
||||
{children}
|
||||
</Nav>
|
||||
</Sticky>
|
||||
</LayoutGroup>
|
||||
</TabsGroup>
|
||||
);
|
||||
};
|
||||
@@ -1,2 +1,2 @@
|
||||
export { Tab } from "./Tab";
|
||||
export { Separator, Tabs } from "./Tabs";
|
||||
export { Separator, Tabs, TabsGroup } from "./Tabs";
|
||||
Reference in new issue
Block a user