From 062f7d24666b697f84101d842c57b610ad357649 Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Fri, 6 Nov 2026 10:54:18 +0300 Subject: [PATCH 01/37] feat(tooltip)!: redesign tooltip component BREAKING CHANGE: Replace tooltip container, arrow and animated props with the new API. Text is required and shape and appearance use new models. --- .pnp.cjs | 3 +- ui-parts/tooltip/package.json | 5 +- ui-parts/tooltip/src/arrow/component.tsx | 27 ++-- ui-parts/tooltip/src/arrow/index.ts | 2 - ui-parts/tooltip/src/arrow/interfaces.ts | 12 +- .../src/arrow/styles/appearance/interfaces.ts | 3 + .../src/arrow/styles/appearance/styles.css.ts | 5 + .../src/arrow/styles/appearance/variants.ts | 7 ++ .../src/arrow/styles/shape/constants.ts | 2 + .../src/arrow/styles/shape/interfaces.ts | 4 + .../src/arrow/styles/shape/variants.ts | 9 ++ ui-parts/tooltip/src/box/component.tsx | 12 ++ .../src/box/styles/appearance/interfaces.ts | 4 + .../src/box/styles/appearance/styles.css.ts | 11 ++ .../src/box/styles/appearance/variants.ts | 13 ++ ui-parts/tooltip/src/box/styles/base.css.ts | 3 + .../tooltip/src/box/styles/shape/constants.ts | 1 + .../src/box/styles/shape/interfaces.ts | 8 ++ .../tooltip/src/box/styles/shape/variants.ts | 15 +++ ui-parts/tooltip/src/component.tsx | 119 ++++++++++-------- ui-parts/tooltip/src/constants.ts | 16 +-- ui-parts/tooltip/src/container/component.tsx | 24 +++- .../tooltip/src/container/container.css.ts | 9 -- ui-parts/tooltip/src/container/index.ts | 1 - ui-parts/tooltip/src/container/interfaces.ts | 11 ++ .../src/container/styles/animation.css.ts | 18 +++ .../tooltip/src/container/styles/base.css.ts | 5 + .../src/container/styles/shape/interfaces.ts | 3 + .../src/container/styles/shape/variants.ts | 7 ++ ui-parts/tooltip/src/index.ts | 11 +- ui-parts/tooltip/src/interfaces.ts | 39 +++--- ui-parts/tooltip/src/styles/appearance.css.ts | 22 ---- .../src/styles/appearance/interfaces.ts | 9 ++ .../tooltip/src/styles/appearance/resolve.ts | 23 ++++ .../tooltip/src/styles/appearance/variants.ts | 15 +++ ui-parts/tooltip/src/styles/index.ts | 2 - ui-parts/tooltip/src/styles/shape.css.ts | 26 ---- .../tooltip/src/styles/shape/interfaces.ts | 11 ++ ui-parts/tooltip/src/styles/shape/variants.ts | 15 +++ ui-parts/tooltip/src/text/component.tsx | 11 ++ .../src/text/styles/appearance/interfaces.ts | 3 + .../src/text/styles/appearance/styles.css.ts | 5 + .../src/text/styles/appearance/variants.ts | 7 ++ .../src/text/styles/shape/interfaces.ts | 5 + .../src/text/styles/shape/variants.css.ts | 7 ++ ui-parts/tooltip/src/useTooltipOpen.ts | 52 ++++++++ yarn.lock | 3 +- 47 files changed, 440 insertions(+), 185 deletions(-) delete mode 100644 ui-parts/tooltip/src/arrow/index.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/appearance/interfaces.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/appearance/styles.css.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/appearance/variants.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/shape/constants.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/shape/interfaces.ts create mode 100644 ui-parts/tooltip/src/arrow/styles/shape/variants.ts create mode 100644 ui-parts/tooltip/src/box/component.tsx create mode 100644 ui-parts/tooltip/src/box/styles/appearance/interfaces.ts create mode 100644 ui-parts/tooltip/src/box/styles/appearance/styles.css.ts create mode 100644 ui-parts/tooltip/src/box/styles/appearance/variants.ts create mode 100644 ui-parts/tooltip/src/box/styles/base.css.ts create mode 100644 ui-parts/tooltip/src/box/styles/shape/constants.ts create mode 100644 ui-parts/tooltip/src/box/styles/shape/interfaces.ts create mode 100644 ui-parts/tooltip/src/box/styles/shape/variants.ts delete mode 100644 ui-parts/tooltip/src/container/container.css.ts delete mode 100644 ui-parts/tooltip/src/container/index.ts create mode 100644 ui-parts/tooltip/src/container/interfaces.ts create mode 100644 ui-parts/tooltip/src/container/styles/animation.css.ts create mode 100644 ui-parts/tooltip/src/container/styles/base.css.ts create mode 100644 ui-parts/tooltip/src/container/styles/shape/interfaces.ts create mode 100644 ui-parts/tooltip/src/container/styles/shape/variants.ts delete mode 100644 ui-parts/tooltip/src/styles/appearance.css.ts create mode 100644 ui-parts/tooltip/src/styles/appearance/interfaces.ts create mode 100644 ui-parts/tooltip/src/styles/appearance/resolve.ts create mode 100644 ui-parts/tooltip/src/styles/appearance/variants.ts delete mode 100644 ui-parts/tooltip/src/styles/index.ts delete mode 100644 ui-parts/tooltip/src/styles/shape.css.ts create mode 100644 ui-parts/tooltip/src/styles/shape/interfaces.ts create mode 100644 ui-parts/tooltip/src/styles/shape/variants.ts create mode 100644 ui-parts/tooltip/src/text/component.tsx create mode 100644 ui-parts/tooltip/src/text/styles/appearance/interfaces.ts create mode 100644 ui-parts/tooltip/src/text/styles/appearance/styles.css.ts create mode 100644 ui-parts/tooltip/src/text/styles/appearance/variants.ts create mode 100644 ui-parts/tooltip/src/text/styles/shape/interfaces.ts create mode 100644 ui-parts/tooltip/src/text/styles/shape/variants.css.ts create mode 100644 ui-parts/tooltip/src/useTooltipOpen.ts diff --git a/.pnp.cjs b/.pnp.cjs index 9b6ae197a..7b105e8b9 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -1989,17 +1989,16 @@ const RAW_RUNTIME_STATE = ["workspace:ui-parts/tooltip", {\ "packageLocation": "./ui-parts/tooltip/",\ "packageDependencies": [\ - ["@atls-ui-parts/condition", "virtual:06315aec6049f1c6c32004d6e584058ffedd6c8eaf08aaee2ce03aaedeaf84c340968f24d92b3566001c478f3ac64eca59adabd63e33390cb5990761978a1ea2#workspace:ui-parts/condition"],\ ["@atls-ui-parts/layout", "virtual:76ebc481ac02aa95961a7136f7e551f7070fbf8eb171c0ca48399e504fe0f0f0edaf1d4f5953b763ae0b309e0e91ebf7d54e047cc0a0270d8aee71a756c50a70#workspace:ui-parts/layout"],\ ["@atls-ui-parts/theme", "virtual:6e3d13d4bb141546c851eafb803659d9bef8a8a4b826ab761e48399dcbf8cda80227a38097da69531ddae63c1380c43a5fad649d9ff8e485d2bc4c96720b9bd0#workspace:ui-parts/theme"],\ ["@atls-ui-parts/tooltip", "workspace:ui-parts/tooltip"],\ + ["@atls-ui/theme", "workspace:ui/theme"],\ ["@atls-utils/use-float", "virtual:e8b379d238bee0c446fdeaddb9725553fcee91eeb8db9f1f4b47e4e36a5c6c26c07ae1861b7d0a5dd574863bc008f048d25fc793392ceeaade0c9801b921d418#workspace:utils/use-float"],\ ["@floating-ui/react", "virtual:bdec61daa5ce18b211e41086a87aa58babcd016eed745eb318a2389812d34b0215bd01c4e05f4de11cfc30bd0259efe6cace4826920dba58cacb6c2dd7978d3e#npm:0.27.8"],\ ["@storybook/react", "virtual:76ebc481ac02aa95961a7136f7e551f7070fbf8eb171c0ca48399e504fe0f0f0edaf1d4f5953b763ae0b309e0e91ebf7d54e047cc0a0270d8aee71a756c50a70#patch:@storybook/react@npm%3A10.4.6#~/.yarn/patches/@storybook-react-npm-10.4.6-574597d2a0.patch::version=10.4.6&hash=1496cc"],\ ["@types/react", "npm:19.1.2"],\ ["@vanilla-extract/css", "npm:1.17.1"],\ ["@vanilla-extract/dynamic", "npm:2.1.2"],\ - ["framer-motion", "virtual:06315aec6049f1c6c32004d6e584058ffedd6c8eaf08aaee2ce03aaedeaf84c340968f24d92b3566001c478f3ac64eca59adabd63e33390cb5990761978a1ea2#npm:12.43.0"],\ ["react", "npm:19.1.0"],\ ["react-dom", "virtual:76ebc481ac02aa95961a7136f7e551f7070fbf8eb171c0ca48399e504fe0f0f0edaf1d4f5953b763ae0b309e0e91ebf7d54e047cc0a0270d8aee71a756c50a70#npm:19.1.0"],\ ["storybook", "virtual:76ebc481ac02aa95961a7136f7e551f7070fbf8eb171c0ca48399e504fe0f0f0edaf1d4f5953b763ae0b309e0e91ebf7d54e047cc0a0270d8aee71a756c50a70#npm:10.4.6"],\ diff --git a/ui-parts/tooltip/package.json b/ui-parts/tooltip/package.json index 29c049042..baffdf3dc 100644 --- a/ui-parts/tooltip/package.json +++ b/ui-parts/tooltip/package.json @@ -13,11 +13,10 @@ "postpack": "rm -rf dist" }, "dependencies": { - "@atls-ui-parts/condition": "workspace:*", "@atls-ui-parts/theme": "workspace:*", + "@atls-ui/theme": "workspace:*", "@atls-utils/use-float": "workspace:*", - "@floating-ui/react": "0.27.8", - "framer-motion": "12.43.0" + "@floating-ui/react": "0.27.8" }, "devDependencies": { "@atls-ui-parts/layout": "workspace:*", diff --git a/ui-parts/tooltip/src/arrow/component.tsx b/ui-parts/tooltip/src/arrow/component.tsx index 5d335d5e8..d46d41977 100644 --- a/ui-parts/tooltip/src/arrow/component.tsx +++ b/ui-parts/tooltip/src/arrow/component.tsx @@ -1,19 +1,18 @@ -import type { ReactNode } from 'react' +import type { ReactNode } from 'react' -import type { ArrowProps } from './interfaces.js' +import type { ArrowProps } from './interfaces.js' -import { FloatingArrow } from '@floating-ui/react' +import { FloatingArrow } from '@floating-ui/react' -import { Condition } from '@atls-ui-parts/condition' +import { arrowAppearanceStyles } from './styles/appearance/styles.css.js' -export const Arrow = ({ ref, context, arrow = true }: ArrowProps): ReactNode => ( - - - +export const Arrow = ({ context, arrowRef, shape }: ArrowProps): ReactNode => ( + ) diff --git a/ui-parts/tooltip/src/arrow/index.ts b/ui-parts/tooltip/src/arrow/index.ts deleted file mode 100644 index 6958544a7..000000000 --- a/ui-parts/tooltip/src/arrow/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './component.js' -export type * from './interfaces.js' diff --git a/ui-parts/tooltip/src/arrow/interfaces.ts b/ui-parts/tooltip/src/arrow/interfaces.ts index 2505759be..6441e5850 100644 --- a/ui-parts/tooltip/src/arrow/interfaces.ts +++ b/ui-parts/tooltip/src/arrow/interfaces.ts @@ -1,9 +1,9 @@ -import type { FloatingArrowProps } from '@floating-ui/react' -import type { UseFloatingReturn } from '@floating-ui/react' -import type { RefObject } from 'react' +import type { UseFloatReturn } from '@atls-utils/use-float' + +import type { ArrowShape } from './styles/shape/interfaces.js' export interface ArrowProps { - ref: RefObject - arrow?: Omit | boolean - context: UseFloatingReturn['context'] + context: UseFloatReturn['context'] + arrowRef: UseFloatReturn['arrowRef'] + shape: ArrowShape } diff --git a/ui-parts/tooltip/src/arrow/styles/appearance/interfaces.ts b/ui-parts/tooltip/src/arrow/styles/appearance/interfaces.ts new file mode 100644 index 000000000..e3a0ac21b --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/appearance/interfaces.ts @@ -0,0 +1,3 @@ +export interface ArrowAppearance { + color: string +} diff --git a/ui-parts/tooltip/src/arrow/styles/appearance/styles.css.ts b/ui-parts/tooltip/src/arrow/styles/appearance/styles.css.ts new file mode 100644 index 000000000..cbb535e1e --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/appearance/styles.css.ts @@ -0,0 +1,5 @@ +import { createThemeContract } from '@vanilla-extract/css' +import { style } from '@vanilla-extract/css' + +export const arrowAppearanceVariables = createThemeContract({ color: null }) +export const arrowAppearanceStyles = style({ fill: arrowAppearanceVariables.color }) diff --git a/ui-parts/tooltip/src/arrow/styles/appearance/variants.ts b/ui-parts/tooltip/src/arrow/styles/appearance/variants.ts new file mode 100644 index 000000000..17c711d21 --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/appearance/variants.ts @@ -0,0 +1,7 @@ +import type { Theme } from '@atls-ui/theme' + +import type { ArrowAppearance } from './interfaces.js' + +export const arrowAppearances: Record<'default', (theme: Theme) => ArrowAppearance> = { + default: (theme) => ({ color: theme.colors.surface.soft }), +} diff --git a/ui-parts/tooltip/src/arrow/styles/shape/constants.ts b/ui-parts/tooltip/src/arrow/styles/shape/constants.ts new file mode 100644 index 000000000..9d4f0744f --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/shape/constants.ts @@ -0,0 +1,2 @@ +export const DEFAULT_ARROW_WIDTH = 12 +export const DEFAULT_ARROW_HEIGHT = 6 diff --git a/ui-parts/tooltip/src/arrow/styles/shape/interfaces.ts b/ui-parts/tooltip/src/arrow/styles/shape/interfaces.ts new file mode 100644 index 000000000..f7b162169 --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/shape/interfaces.ts @@ -0,0 +1,4 @@ +export interface ArrowShape { + width: number + height: number +} diff --git a/ui-parts/tooltip/src/arrow/styles/shape/variants.ts b/ui-parts/tooltip/src/arrow/styles/shape/variants.ts new file mode 100644 index 000000000..ab49003a0 --- /dev/null +++ b/ui-parts/tooltip/src/arrow/styles/shape/variants.ts @@ -0,0 +1,9 @@ +import type { ArrowShape } from './interfaces.js' + +import { DEFAULT_ARROW_HEIGHT } from './constants.js' + +import { DEFAULT_ARROW_WIDTH } from './constants.js' + +export const arrowShapes: Record<'default', ArrowShape> = { + default: { width: DEFAULT_ARROW_WIDTH, height: DEFAULT_ARROW_HEIGHT }, +} diff --git a/ui-parts/tooltip/src/box/component.tsx b/ui-parts/tooltip/src/box/component.tsx new file mode 100644 index 000000000..994be37bc --- /dev/null +++ b/ui-parts/tooltip/src/box/component.tsx @@ -0,0 +1,12 @@ +import type { ReactNode } from 'react' + +import type { BoxShape } from './styles/shape/interfaces.js' + +import { boxAppearanceStyles } from './styles/appearance/styles.css.js' +import { boxBaseStyles } from './styles/base.css.js' + +export const Box = ({ children, shape }: { children: ReactNode; shape: BoxShape }): ReactNode => ( +
+ {children} +
+) diff --git a/ui-parts/tooltip/src/box/styles/appearance/interfaces.ts b/ui-parts/tooltip/src/box/styles/appearance/interfaces.ts new file mode 100644 index 000000000..2ba2739b2 --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/appearance/interfaces.ts @@ -0,0 +1,4 @@ +export interface BoxAppearance { + backgroundColor: string + shadow: string +} diff --git a/ui-parts/tooltip/src/box/styles/appearance/styles.css.ts b/ui-parts/tooltip/src/box/styles/appearance/styles.css.ts new file mode 100644 index 000000000..1b478435c --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/appearance/styles.css.ts @@ -0,0 +1,11 @@ +import { createThemeContract } from '@vanilla-extract/css' +import { style } from '@vanilla-extract/css' + +export const boxAppearanceVariables = createThemeContract({ + backgroundColor: null, + shadow: null, +}) +export const boxAppearanceStyles = style({ + backgroundColor: boxAppearanceVariables.backgroundColor, + filter: boxAppearanceVariables.shadow, +}) diff --git a/ui-parts/tooltip/src/box/styles/appearance/variants.ts b/ui-parts/tooltip/src/box/styles/appearance/variants.ts new file mode 100644 index 000000000..c8cc82c59 --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/appearance/variants.ts @@ -0,0 +1,13 @@ +import type { Theme } from '@atls-ui/theme' + +import type { BoxAppearance } from './interfaces.js' + +import { shadowBlurs } from '@atls-ui/theme/tokens' +import { shadowOffsets } from '@atls-ui/theme/tokens' + +export const boxAppearances: Record<'default', (theme: Theme) => BoxAppearance> = { + default: (theme) => ({ + backgroundColor: theme.colors.surface.soft, + shadow: `drop-shadow(${shadowOffsets.none} ${shadowOffsets.xs} calc(${shadowBlurs.xs4} / 2) ${theme.colors.elevation.xs})`, + }), +} diff --git a/ui-parts/tooltip/src/box/styles/base.css.ts b/ui-parts/tooltip/src/box/styles/base.css.ts new file mode 100644 index 000000000..e049901f2 --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/base.css.ts @@ -0,0 +1,3 @@ +import { style } from '@vanilla-extract/css' + +export const boxBaseStyles = style({ boxSizing: 'border-box' }) diff --git a/ui-parts/tooltip/src/box/styles/shape/constants.ts b/ui-parts/tooltip/src/box/styles/shape/constants.ts new file mode 100644 index 000000000..f24689b19 --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/shape/constants.ts @@ -0,0 +1 @@ +export const DEFAULT_MAX_WIDTH = '200px' diff --git a/ui-parts/tooltip/src/box/styles/shape/interfaces.ts b/ui-parts/tooltip/src/box/styles/shape/interfaces.ts new file mode 100644 index 000000000..2f6ab84bc --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/shape/interfaces.ts @@ -0,0 +1,8 @@ +import type { CSSProperties } from 'react' + +export interface BoxShape { + borderRadius: CSSProperties['borderRadius'] + maxWidth: CSSProperties['maxWidth'] + paddingBlock: CSSProperties['paddingBlock'] + paddingInline: CSSProperties['paddingInline'] +} diff --git a/ui-parts/tooltip/src/box/styles/shape/variants.ts b/ui-parts/tooltip/src/box/styles/shape/variants.ts new file mode 100644 index 000000000..07e4180f4 --- /dev/null +++ b/ui-parts/tooltip/src/box/styles/shape/variants.ts @@ -0,0 +1,15 @@ +import type { BoxShape } from './interfaces.js' + +import { radii } from '@atls-ui/theme/tokens' +import { spacing } from '@atls-ui/theme/tokens' + +import { DEFAULT_MAX_WIDTH } from './constants.js' + +export const boxShapes: Record<'default', BoxShape> = { + default: { + borderRadius: radii.xs2, + maxWidth: DEFAULT_MAX_WIDTH, + paddingBlock: spacing.component.xs, + paddingInline: spacing.component.md, + }, +} diff --git a/ui-parts/tooltip/src/component.tsx b/ui-parts/tooltip/src/component.tsx index 53d366511..45c4a758f 100644 --- a/ui-parts/tooltip/src/component.tsx +++ b/ui-parts/tooltip/src/component.tsx @@ -1,70 +1,81 @@ -import type { ReactNode } from 'react' +import type { ReactNode } from 'react' -import type { TooltipProps } from './interfaces.js' +import type { TooltipProps } from './interfaces.js' -import { FloatingPortal } from '@floating-ui/react' -import { AnimatePresence } from 'framer-motion' -import { motion } from 'framer-motion' -import { cloneElement } from 'react' +import { FloatingPortal } from '@floating-ui/react' +import { useMergeRefs } from '@floating-ui/react' +import { useTransitionStatus } from '@floating-ui/react' +import { cloneElement } from 'react' -import { useFloat } from '@atls-utils/use-float' +import { useTheme } from '@atls-ui-parts/theme' +import { useFloat } from '@atls-utils/use-float' -import { Arrow } from './arrow/index.js' -import { Container } from './container/index.js' -import { animateProps } from './constants.js' -import { tooltipAppearances } from './styles/index.js' -import { tooltipShapes } from './styles/index.js' +import { Arrow } from './arrow/component.js' +import { Box } from './box/component.js' +import { DEFAULT_PRESS_OPEN_DURATION } from './constants.js' +import { TOOLTIP_ANIMATION_DURATION } from './constants.js' +import { Container } from './container/component.js' +import { Text } from './text/component.js' +import { resolveTooltipAppearance } from './styles/appearance/resolve.js' +import { tooltipShapes } from './styles/shape/variants.js' +import { useTooltipOpen } from './useTooltipOpen.js' export const Tooltip = ({ - appearance, children, text, open, - container, - animated = true, - arrow = true, - shape, - ...props + onOpenChange, + placement = 'top', + trigger = 'hover', + pressOpenDuration = DEFAULT_PRESS_OPEN_DURATION, + appearance = 'default', + shape = tooltipShapes.default, + mouseEnterDelay, + mouseLeaveDelay, }: TooltipProps): ReactNode => { - const { arrowRef, refs, isOpen, context, floatingStyles, getFloatingProps, getReferenceProps } = - useFloat({ open, role: 'tooltip', ...props }) - - const defaultContainer = container === undefined - const containerElement = container ?? - const TriggerElement = cloneElement(children, { ref: refs.setReference, ...getReferenceProps() }) - const containerClassName = [ - containerElement.props.className, - defaultContainer && tooltipAppearances.default.container, - defaultContainer && tooltipShapes.default.container, - appearance?.container, - shape?.container, - ] - .filter(Boolean) - .join(' ') - - const ContainerElement = cloneElement( - containerElement, - { className: containerClassName || undefined, open: isOpen }, - <> - - {text} - - ) - - const motionProps = typeof animated === 'boolean' ? animateProps : animated + const theme = useTheme() + const tooltipOpen = useTooltipOpen(open, onOpenChange, trigger, pressOpenDuration) + const { refs, arrowRef, context, isOpen, floatingStyles, getReferenceProps, getFloatingProps } = + useFloat({ + open: tooltipOpen.open, + onOpenChange: tooltipOpen.onOpenChange, + placement, + offset: shape.container.offset, + trigger: trigger === 'hover' ? 'hover' : 'click', + role: 'tooltip', + mouseEnterDelay, + mouseLeaveDelay, + }) + const { isMounted, status } = useTransitionStatus(context, { + duration: TOOLTIP_ANIMATION_DURATION, + }) + const triggerRef = useMergeRefs([children.props.ref, refs.setReference]) + const triggerElement = cloneElement(children, { + ...getReferenceProps(children.props), + ref: triggerRef, + }) return ( <> - {TriggerElement} - -
- - {!!isOpen && ( - {ContainerElement} - )} - -
-
+ {triggerElement} + {isMounted && ( + + + + + + + + + )} ) } diff --git a/ui-parts/tooltip/src/constants.ts b/ui-parts/tooltip/src/constants.ts index 5f92436e2..5941a2a9d 100644 --- a/ui-parts/tooltip/src/constants.ts +++ b/ui-parts/tooltip/src/constants.ts @@ -1,14 +1,4 @@ -import type { MotionProps } from 'framer-motion' +import { animations } from '@atls-ui/theme/tokens' -export const DEFAULT_CONTAINER_HEIGHT = 32 - -export const DEFAULT_CONTAINER_MIN_WIDTH = 30 - -export const DEFAULT_CONTAINER_Z_INDEX = 1000 - -export const animateProps: MotionProps = { - initial: { opacity: 0, scale: 0.8 }, - animate: { opacity: 1, scale: 1 }, - exit: { opacity: 0, scale: 0.8 }, - transition: { type: 'spring', damping: 30, stiffness: 500 }, -} +export const DEFAULT_PRESS_OPEN_DURATION = 2000 +export const TOOLTIP_ANIMATION_DURATION = Number.parseFloat(animations.duration.sm) diff --git a/ui-parts/tooltip/src/container/component.tsx b/ui-parts/tooltip/src/container/component.tsx index aec564602..90d56a827 100644 --- a/ui-parts/tooltip/src/container/component.tsx +++ b/ui-parts/tooltip/src/container/component.tsx @@ -1,8 +1,22 @@ -import type { HTMLAttributes } from 'react' -import type { ReactNode } from 'react' +import type { ReactNode } from 'react' -import { baseContainerStyles } from './container.css.js' +import type { ContainerProps } from './interfaces.js' -export const Container = ({ className, ...props }: HTMLAttributes): ReactNode => ( -
+import { containerAnimationStyles } from './styles/animation.css.js' +import { containerBaseStyles } from './styles/base.css.js' + +export const Container = ({ + ref, + floatingStyles, + shape, + style, + className, + ...props +}: ContainerProps): ReactNode => ( +
) diff --git a/ui-parts/tooltip/src/container/container.css.ts b/ui-parts/tooltip/src/container/container.css.ts deleted file mode 100644 index bb1d76e11..000000000 --- a/ui-parts/tooltip/src/container/container.css.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { style } from '@vanilla-extract/css' - -export const baseContainerStyles = style({ - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - margin: 0, - wordWrap: 'break-word', -}) diff --git a/ui-parts/tooltip/src/container/index.ts b/ui-parts/tooltip/src/container/index.ts deleted file mode 100644 index b7a151031..000000000 --- a/ui-parts/tooltip/src/container/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './component.js' diff --git a/ui-parts/tooltip/src/container/interfaces.ts b/ui-parts/tooltip/src/container/interfaces.ts new file mode 100644 index 000000000..40d3813ad --- /dev/null +++ b/ui-parts/tooltip/src/container/interfaces.ts @@ -0,0 +1,11 @@ +import type { CSSProperties } from 'react' +import type { HTMLAttributes } from 'react' +import type { Ref } from 'react' + +import type { ContainerShape } from './styles/shape/interfaces.js' + +export interface ContainerProps extends HTMLAttributes { + ref?: Ref + floatingStyles: CSSProperties + shape: ContainerShape +} diff --git a/ui-parts/tooltip/src/container/styles/animation.css.ts b/ui-parts/tooltip/src/container/styles/animation.css.ts new file mode 100644 index 000000000..de17d4501 --- /dev/null +++ b/ui-parts/tooltip/src/container/styles/animation.css.ts @@ -0,0 +1,18 @@ +import { style } from '@vanilla-extract/css' + +import { animations } from '@atls-ui/theme/tokens' +import { opacity } from '@atls-ui/theme/tokens' + +export const containerAnimationStyles = style({ + opacity: opacity.full, + transition: `opacity ${animations.duration.sm} ${animations.easing.easeOut}`, + selectors: { + '&[data-transition="initial"]': { opacity: opacity.none }, + '&[data-transition="close"]': { opacity: opacity.none, pointerEvents: 'none' }, + }, + '@media': { + '(prefers-reduced-motion: reduce)': { + transitionDuration: animations.duration.none, + }, + }, +}) diff --git a/ui-parts/tooltip/src/container/styles/base.css.ts b/ui-parts/tooltip/src/container/styles/base.css.ts new file mode 100644 index 000000000..a4ee1910d --- /dev/null +++ b/ui-parts/tooltip/src/container/styles/base.css.ts @@ -0,0 +1,5 @@ +import { style } from '@vanilla-extract/css' + +import { zIndex } from '@atls-ui/theme' + +export const containerBaseStyles = style({ zIndex: zIndex.overlay, width: 'max-content' }) diff --git a/ui-parts/tooltip/src/container/styles/shape/interfaces.ts b/ui-parts/tooltip/src/container/styles/shape/interfaces.ts new file mode 100644 index 000000000..53b0088ff --- /dev/null +++ b/ui-parts/tooltip/src/container/styles/shape/interfaces.ts @@ -0,0 +1,3 @@ +export interface ContainerShape { + offset: number +} diff --git a/ui-parts/tooltip/src/container/styles/shape/variants.ts b/ui-parts/tooltip/src/container/styles/shape/variants.ts new file mode 100644 index 000000000..4cab34eab --- /dev/null +++ b/ui-parts/tooltip/src/container/styles/shape/variants.ts @@ -0,0 +1,7 @@ +import type { ContainerShape } from './interfaces.js' + +import { spacing } from '@atls-ui/theme/tokens' + +export const containerShapes: Record<'default', ContainerShape> = { + default: { offset: Number.parseFloat(spacing.component.md) }, +} diff --git a/ui-parts/tooltip/src/index.ts b/ui-parts/tooltip/src/index.ts index 728040950..bd9360fba 100644 --- a/ui-parts/tooltip/src/index.ts +++ b/ui-parts/tooltip/src/index.ts @@ -1,4 +1,7 @@ -export * from './arrow/index.js' -export * from './component.js' -export * from './styles/index.js' -export type * from './interfaces.js' +export { Tooltip } from './component.js' +export type { TooltipProps, TooltipPlacement, TooltipTrigger } from './interfaces.js' +export type { TooltipAppearance } from './styles/appearance/interfaces.js' +export type { TooltipShape } from './styles/shape/interfaces.js' +export type { TextShape } from './text/styles/shape/interfaces.js' +export { tooltipAppearances } from './styles/appearance/variants.js' +export { tooltipShapes } from './styles/shape/variants.js' diff --git a/ui-parts/tooltip/src/interfaces.ts b/ui-parts/tooltip/src/interfaces.ts index d34bd8b24..b93200834 100644 --- a/ui-parts/tooltip/src/interfaces.ts +++ b/ui-parts/tooltip/src/interfaces.ts @@ -1,27 +1,26 @@ import type { UseFloatProps } from '@atls-utils/use-float' -import type { FloatingArrowProps } from '@floating-ui/react' -import type { MotionProps } from 'framer-motion' -import type { JSX } from 'react' -import type { ReactNode } from 'react' +import type { HTMLAttributes } from 'react' +import type { ReactElement } from 'react' +import type { Ref } from 'react' -export interface TooltipAppearance { - container: string -} - -export type TooltipAppearanceName = 'default' +import type { TooltipAppearance } from './styles/appearance/interfaces.js' +import type { TooltipShape } from './styles/shape/interfaces.js' +import type { tooltipAppearances } from './styles/appearance/variants.js' -export interface TooltipShape { - container: string -} +export type TooltipPlacement = + 'bottom-end' | 'bottom-start' | 'bottom' | 'left' | 'right' | 'top-end' | 'top-start' | 'top' -export type TooltipShapeName = 'default' +export type TooltipTrigger = 'hover' | 'pressed' -export interface TooltipProps extends UseFloatProps { - appearance?: TooltipAppearance - children: JSX.Element - text?: ReactNode - container?: JSX.Element - animated?: Omit | boolean - arrow?: Omit | boolean +export interface TooltipProps extends Pick< + UseFloatProps, + 'mouseEnterDelay' | 'mouseLeaveDelay' | 'onOpenChange' | 'open' +> { + children: ReactElement & { ref?: Ref }> + text: string + placement?: TooltipPlacement + trigger?: TooltipTrigger + pressOpenDuration?: number + appearance?: TooltipAppearance | keyof typeof tooltipAppearances shape?: TooltipShape } diff --git a/ui-parts/tooltip/src/styles/appearance.css.ts b/ui-parts/tooltip/src/styles/appearance.css.ts deleted file mode 100644 index b81e1bbbd..000000000 --- a/ui-parts/tooltip/src/styles/appearance.css.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { TooltipAppearance } from '../interfaces.js' -import type { TooltipAppearanceName } from '../interfaces.js' - -import { style } from '@vanilla-extract/css' - -import { vars } from '@atls-ui-parts/theme' - -const containerDefaultAppearanceStyles = style({ - color: vars.colors.white, - backgroundColor: vars.colors.blackThreeQuarters, - boxShadow: vars.shadows.gordonsgreen, -}) - -export const appearanceVariant = { - default: { - container: containerDefaultAppearanceStyles, - }, -} - -export const tooltipAppearances: Record = { - default: appearanceVariant.default, -} diff --git a/ui-parts/tooltip/src/styles/appearance/interfaces.ts b/ui-parts/tooltip/src/styles/appearance/interfaces.ts new file mode 100644 index 000000000..3108b9eed --- /dev/null +++ b/ui-parts/tooltip/src/styles/appearance/interfaces.ts @@ -0,0 +1,9 @@ +import type { ArrowAppearance } from '../../arrow/styles/appearance/interfaces.js' +import type { BoxAppearance } from '../../box/styles/appearance/interfaces.js' +import type { TextAppearance } from '../../text/styles/appearance/interfaces.js' + +export interface TooltipAppearance { + box: BoxAppearance + text: TextAppearance + arrow: ArrowAppearance +} diff --git a/ui-parts/tooltip/src/styles/appearance/resolve.ts b/ui-parts/tooltip/src/styles/appearance/resolve.ts new file mode 100644 index 000000000..c4117d459 --- /dev/null +++ b/ui-parts/tooltip/src/styles/appearance/resolve.ts @@ -0,0 +1,23 @@ +import type { Theme } from '@atls-ui/theme' +import type { CSSProperties } from 'react' + +import type { TooltipAppearance } from './interfaces.js' + +import { assignInlineVars } from '@vanilla-extract/dynamic' + +import { arrowAppearanceVariables } from '../../arrow/styles/appearance/styles.css.js' +import { boxAppearanceVariables } from '../../box/styles/appearance/styles.css.js' +import { textAppearanceVariables } from '../../text/styles/appearance/styles.css.js' +import { tooltipAppearances } from './variants.js' + +export const resolveTooltipAppearance = ( + appearance: TooltipAppearance | keyof typeof tooltipAppearances, + theme: Theme +): CSSProperties => { + const values = typeof appearance === 'string' ? tooltipAppearances[appearance](theme) : appearance + return { + ...assignInlineVars(boxAppearanceVariables, values.box), + ...assignInlineVars(textAppearanceVariables, values.text), + ...assignInlineVars(arrowAppearanceVariables, values.arrow), + } +} diff --git a/ui-parts/tooltip/src/styles/appearance/variants.ts b/ui-parts/tooltip/src/styles/appearance/variants.ts new file mode 100644 index 000000000..4ed3ceccd --- /dev/null +++ b/ui-parts/tooltip/src/styles/appearance/variants.ts @@ -0,0 +1,15 @@ +import type { Theme } from '@atls-ui/theme' + +import type { TooltipAppearance } from './interfaces.js' + +import { arrowAppearances } from '../../arrow/styles/appearance/variants.js' +import { boxAppearances } from '../../box/styles/appearance/variants.js' +import { textAppearances } from '../../text/styles/appearance/variants.js' + +export const tooltipAppearances = { + default: (theme: Theme): TooltipAppearance => ({ + box: boxAppearances.default(theme), + text: textAppearances.default(theme), + arrow: arrowAppearances.default(theme), + }), +} diff --git a/ui-parts/tooltip/src/styles/index.ts b/ui-parts/tooltip/src/styles/index.ts deleted file mode 100644 index 93e0eec5d..000000000 --- a/ui-parts/tooltip/src/styles/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './appearance.css.js' -export * from './shape.css.js' diff --git a/ui-parts/tooltip/src/styles/shape.css.ts b/ui-parts/tooltip/src/styles/shape.css.ts deleted file mode 100644 index 8a2ca6655..000000000 --- a/ui-parts/tooltip/src/styles/shape.css.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TooltipShape } from '../interfaces.js' -import type { TooltipShapeName } from '../interfaces.js' - -import { style } from '@vanilla-extract/css' - -import { vars } from '@atls-ui-parts/theme' - -import { DEFAULT_CONTAINER_HEIGHT } from '../constants.js' -import { DEFAULT_CONTAINER_MIN_WIDTH } from '../constants.js' -import { DEFAULT_CONTAINER_Z_INDEX } from '../constants.js' - -const containerDefaultShapeStyles = style({ - minWidth: DEFAULT_CONTAINER_MIN_WIDTH, - minHeight: DEFAULT_CONTAINER_HEIGHT, - padding: `${vars.space.g8} ${vars.space.g12}`, - borderRadius: vars.radii.f8, - zIndex: DEFAULT_CONTAINER_Z_INDEX, -}) - -export const shapeStyles = { - default: { - container: containerDefaultShapeStyles, - }, -} - -export const tooltipShapes: Record = shapeStyles diff --git a/ui-parts/tooltip/src/styles/shape/interfaces.ts b/ui-parts/tooltip/src/styles/shape/interfaces.ts new file mode 100644 index 000000000..88d784070 --- /dev/null +++ b/ui-parts/tooltip/src/styles/shape/interfaces.ts @@ -0,0 +1,11 @@ +import type { ArrowShape } from '../../arrow/styles/shape/interfaces.js' +import type { BoxShape } from '../../box/styles/shape/interfaces.js' +import type { ContainerShape } from '../../container/styles/shape/interfaces.js' +import type { TextShape } from '../../text/styles/shape/interfaces.js' + +export interface TooltipShape { + container: ContainerShape + box: BoxShape + text: TextShape + arrow: ArrowShape +} diff --git a/ui-parts/tooltip/src/styles/shape/variants.ts b/ui-parts/tooltip/src/styles/shape/variants.ts new file mode 100644 index 000000000..f30433029 --- /dev/null +++ b/ui-parts/tooltip/src/styles/shape/variants.ts @@ -0,0 +1,15 @@ +import type { TooltipShape } from './interfaces.js' + +import { arrowShapes } from '../../arrow/styles/shape/variants.js' +import { boxShapes } from '../../box/styles/shape/variants.js' +import { containerShapes } from '../../container/styles/shape/variants.js' +import { textShapes } from '../../text/styles/shape/variants.css.js' + +export const tooltipShapes: Record<'default', TooltipShape> = { + default: { + container: containerShapes.default, + box: boxShapes.default, + text: textShapes.default, + arrow: arrowShapes.default, + }, +} diff --git a/ui-parts/tooltip/src/text/component.tsx b/ui-parts/tooltip/src/text/component.tsx new file mode 100644 index 000000000..7f985c082 --- /dev/null +++ b/ui-parts/tooltip/src/text/component.tsx @@ -0,0 +1,11 @@ +import type { ReactNode } from 'react' + +import type { TextShape } from './styles/shape/interfaces.js' + +import { textAppearanceStyles } from './styles/appearance/styles.css.js' + +export const Text = ({ text, shape }: { text: string; shape: TextShape }): ReactNode => ( + + {text} + +) diff --git a/ui-parts/tooltip/src/text/styles/appearance/interfaces.ts b/ui-parts/tooltip/src/text/styles/appearance/interfaces.ts new file mode 100644 index 000000000..508d61300 --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/appearance/interfaces.ts @@ -0,0 +1,3 @@ +export interface TextAppearance { + color: string +} diff --git a/ui-parts/tooltip/src/text/styles/appearance/styles.css.ts b/ui-parts/tooltip/src/text/styles/appearance/styles.css.ts new file mode 100644 index 000000000..f6ff05d80 --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/appearance/styles.css.ts @@ -0,0 +1,5 @@ +import { createThemeContract } from '@vanilla-extract/css' +import { style } from '@vanilla-extract/css' + +export const textAppearanceVariables = createThemeContract({ color: null }) +export const textAppearanceStyles = style({ color: textAppearanceVariables.color }) diff --git a/ui-parts/tooltip/src/text/styles/appearance/variants.ts b/ui-parts/tooltip/src/text/styles/appearance/variants.ts new file mode 100644 index 000000000..364ae220b --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/appearance/variants.ts @@ -0,0 +1,7 @@ +import type { Theme } from '@atls-ui/theme' + +import type { TextAppearance } from './interfaces.js' + +export const textAppearances: Record<'default', (theme: Theme) => TextAppearance> = { + default: (theme) => ({ color: theme.colors.text.primary }), +} diff --git a/ui-parts/tooltip/src/text/styles/shape/interfaces.ts b/ui-parts/tooltip/src/text/styles/shape/interfaces.ts new file mode 100644 index 000000000..399a10cce --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/shape/interfaces.ts @@ -0,0 +1,5 @@ +import type { CSSProperties } from 'react' + +export interface TextShape { + typography: CSSProperties +} diff --git a/ui-parts/tooltip/src/text/styles/shape/variants.css.ts b/ui-parts/tooltip/src/text/styles/shape/variants.css.ts new file mode 100644 index 000000000..5a8e39ed3 --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/shape/variants.css.ts @@ -0,0 +1,7 @@ +import type { TextShape } from './interfaces.js' + +import { typography } from '@atls-ui/theme/tokens' + +export const textShapes: Record<'default', TextShape> = { + default: { typography: typography.body.lg }, +} diff --git a/ui-parts/tooltip/src/useTooltipOpen.ts b/ui-parts/tooltip/src/useTooltipOpen.ts new file mode 100644 index 000000000..6473c73a1 --- /dev/null +++ b/ui-parts/tooltip/src/useTooltipOpen.ts @@ -0,0 +1,52 @@ +import type { UseFloatProps } from '@atls-utils/use-float' + +import type { TooltipTrigger } from './interfaces.js' + +import { useCallback } from 'react' +import { useEffect } from 'react' +import { useRef } from 'react' +import { useState } from 'react' + +type OpenChangeHandler = NonNullable + +export const useTooltipOpen = ( + controlledOpen: boolean | undefined, + onOpenChange: UseFloatProps['onOpenChange'], + trigger: TooltipTrigger, + pressOpenDuration: number +) => { + const [localOpen, setLocalOpen] = useState(false) + const pressTimer = useRef | undefined>(undefined) + + const handleOpenChange: OpenChangeHandler = useCallback( + (nextOpen, event, reason) => { + clearTimeout(pressTimer.current) + if (controlledOpen === undefined) { + setLocalOpen(nextOpen) + } + onOpenChange?.(nextOpen, event, reason) + + if (trigger === 'pressed' && nextOpen && reason === 'click') { + pressTimer.current = setTimeout(() => { + if (controlledOpen === undefined) { + setLocalOpen(false) + } + onOpenChange?.(false) + }, pressOpenDuration) + } + }, + [controlledOpen, onOpenChange, trigger, pressOpenDuration] + ) + + useEffect( + () => () => { + clearTimeout(pressTimer.current) + }, + [] + ) + + return { + open: controlledOpen ?? localOpen, + onOpenChange: handleOpenChange, + } +} diff --git a/yarn.lock b/yarn.lock index 3f9993891..f7736a168 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1094,16 +1094,15 @@ __metadata: version: 0.0.0-use.local resolution: "@atls-ui-parts/tooltip@workspace:ui-parts/tooltip" dependencies: - "@atls-ui-parts/condition": "workspace:*" "@atls-ui-parts/layout": "workspace:*" "@atls-ui-parts/theme": "workspace:*" + "@atls-ui/theme": "workspace:*" "@atls-utils/use-float": "workspace:*" "@floating-ui/react": "npm:0.27.8" "@storybook/react": "npm:10.4.6" "@types/react": "npm:19.1.2" "@vanilla-extract/css": "npm:1.17.1" "@vanilla-extract/dynamic": "npm:2.1.2" - framer-motion: "npm:12.43.0" react: "npm:19.1.0" react-dom: "npm:19.1.0" storybook: "npm:10.4.6" From 84868146438eb16278eed0943891f93ca78fe21d Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Fri, 6 Nov 2026 10:54:38 +0300 Subject: [PATCH 02/37] docs(tooltip): update story for redesigned component --- ui-parts/tooltip/src/stories.tsx | 51 +++++++++ ui-parts/tooltip/stories/interfaces.ts | 9 -- ui-parts/tooltip/stories/styles.css.ts | 25 ---- ui-parts/tooltip/stories/tooltip.stories.tsx | 114 ------------------- 4 files changed, 51 insertions(+), 148 deletions(-) create mode 100644 ui-parts/tooltip/src/stories.tsx delete mode 100644 ui-parts/tooltip/stories/interfaces.ts delete mode 100644 ui-parts/tooltip/stories/styles.css.ts delete mode 100644 ui-parts/tooltip/stories/tooltip.stories.tsx diff --git a/ui-parts/tooltip/src/stories.tsx b/ui-parts/tooltip/src/stories.tsx new file mode 100644 index 000000000..5b96cc81f --- /dev/null +++ b/ui-parts/tooltip/src/stories.tsx @@ -0,0 +1,51 @@ +import type { Meta } from '@storybook/react' +import type { StoryObj } from '@storybook/react' + +import type { TooltipProps } from './interfaces.js' + +import { Tooltip } from './component.js' +import { DEFAULT_PRESS_OPEN_DURATION } from './constants.js' +import { tooltipAppearances } from './styles/appearance/variants.js' +import { tooltipShapes } from './styles/shape/variants.js' + +const meta: Meta = { + title: 'Components/Tooltip', + tags: ['autodocs'], + parameters: { layout: 'centered' }, + render: (props) => ( + + + + ), + argTypes: { + children: { control: false }, + placement: { + control: 'select', + options: [ + 'top', + 'top-start', + 'top-end', + 'bottom', + 'bottom-start', + 'bottom-end', + 'left', + 'right', + ], + }, + appearance: { control: 'select', options: Object.keys(tooltipAppearances) }, + shape: { control: 'select', options: Object.keys(tooltipShapes), mapping: tooltipShapes }, + open: { control: 'boolean' }, + trigger: { control: 'select', options: ['hover', 'pressed'] }, + pressOpenDuration: { control: 'number' }, + }, + args: { + text: 'Tooltip text', + placement: 'top', + trigger: 'hover', + pressOpenDuration: DEFAULT_PRESS_OPEN_DURATION, + appearance: 'default', + shape: tooltipShapes.default, + }, +} +export default meta +export const Base: StoryObj = {} diff --git a/ui-parts/tooltip/stories/interfaces.ts b/ui-parts/tooltip/stories/interfaces.ts deleted file mode 100644 index 482b3b99a..000000000 --- a/ui-parts/tooltip/stories/interfaces.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { TooltipProps } from '@atls-ui-parts/tooltip' - -export interface StoryTooltipProps extends Pick< - TooltipProps, - 'animated' | 'arrow' | 'offset' | 'placement' | 'trigger' -> { - customContainer: boolean - styledContainer: boolean -} diff --git a/ui-parts/tooltip/stories/styles.css.ts b/ui-parts/tooltip/stories/styles.css.ts deleted file mode 100644 index fac105679..000000000 --- a/ui-parts/tooltip/stories/styles.css.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { style } from '@vanilla-extract/css' - -export const storyContainerAppearanceStyles = style({ - background: 'green', - color: 'white', -}) - -export const storyContainerShapeStyles = style({ - width: '150px', - height: '30px', - margin: 0, -}) - -export const storyTriggerStyles = style({ - boxSizing: 'border-box', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - height: '32px', - padding: '0px 16px', - color: 'rgba(0, 0, 0, 0.65)', - backgroundColor: '#fff', - border: '1px solid #d9d9d9', - cursor: 'pointer', -}) diff --git a/ui-parts/tooltip/stories/tooltip.stories.tsx b/ui-parts/tooltip/stories/tooltip.stories.tsx deleted file mode 100644 index 8a0497223..000000000 --- a/ui-parts/tooltip/stories/tooltip.stories.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import type { Meta } from '@storybook/react' -import type { StoryObj } from '@storybook/react' -import type { ReactElement } from 'react' - -import type { StoryTooltipProps } from './interfaces.js' - -import { Tooltip } from '@atls-ui-parts/tooltip' - -import { storyContainerAppearanceStyles } from './styles.css.js' -import { storyContainerShapeStyles } from './styles.css.js' -import { storyTriggerStyles } from './styles.css.js' - -const storyContainerClassName = [storyContainerAppearanceStyles, storyContainerShapeStyles].join( - ' ' -) - -const renderTooltip = ({ - animated, - arrow, - customContainer, - offset, - placement, - styledContainer, - trigger, -}: StoryTooltipProps): ReactElement => ( - : undefined} - > -
Trigger
-
-) - -const meta: Meta = { - title: 'Components/Tooltip', - tags: ['autodocs'], - parameters: { - layout: 'centered', - }, - argTypes: { - animated: { - description: 'Анимированный', - control: { type: 'boolean' }, - }, - arrow: { - description: 'Указатель', - control: { type: 'boolean' }, - }, - customContainer: { - description: 'Свой контейнер', - control: { type: 'boolean' }, - }, - styledContainer: { - description: 'Стили дефолтного контейнера', - control: { type: 'boolean' }, - }, - offset: { - description: 'Офсет', - control: { type: 'number' }, - }, - placement: { - description: 'Расположение', - control: { type: 'select' }, - options: [ - 'top', - 'right', - 'bottom', - 'left', - 'top-end', - 'top-start', - 'right-end', - 'right-start', - 'bottom-end', - 'bottom-start', - 'left-end', - 'left-start', - ], - }, - trigger: { - description: 'Триггер', - control: { type: 'select' }, - options: ['click', 'hover'], - }, - }, - args: { - animated: true, - arrow: true, - customContainer: false, - styledContainer: false, - offset: 10, - placement: 'top', - trigger: 'click', - }, -} - -export default meta - -export const Base: StoryObj = { - render: renderTooltip, -} - -export const StyledContainer: StoryObj = { - args: { - styledContainer: true, - }, - render: renderTooltip, -} From 1d8eb905b68dde4dda5a0c02a9215c0ee39472f2 Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Fri, 6 Nov 2026 10:55:10 +0300 Subject: [PATCH 03/37] fix(components): update tooltip generator template --- .../src/templates/tooltip/component.tsx.hbs | 5 +---- .../src/templates/tooltip/index.ts.hbs | 2 +- .../src/templates/tooltip/styles.css.ts.hbs | 17 ----------------- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 generators/components/src/templates/tooltip/styles.css.ts.hbs diff --git a/generators/components/src/templates/tooltip/component.tsx.hbs b/generators/components/src/templates/tooltip/component.tsx.hbs index ed7f8a282..9bc14ec60 100644 --- a/generators/components/src/templates/tooltip/component.tsx.hbs +++ b/generators/components/src/templates/tooltip/component.tsx.hbs @@ -1,13 +1,10 @@ import type { TooltipProps } from '@atls-ui-parts/tooltip' import type { ReactNode } from 'react' -import { Box } from '@ui/layout' import { Tooltip as BaseTooltip } from '@atls-ui-parts/tooltip' -import { baseContainerStyles } from './styles.css.js' - export const Tooltip = ({ children, ...props }: TooltipProps): ReactNode => ( - }> + {children} ) diff --git a/generators/components/src/templates/tooltip/index.ts.hbs b/generators/components/src/templates/tooltip/index.ts.hbs index 5f14e1213..2f0adba4d 100644 --- a/generators/components/src/templates/tooltip/index.ts.hbs +++ b/generators/components/src/templates/tooltip/index.ts.hbs @@ -1,2 +1,2 @@ export * from './component.js' -export type { TooltipProps, ArrowProps } from '@atls-ui-parts/tooltip' +export type { TooltipProps, TooltipShape, TooltipAppearance } from '@atls-ui-parts/tooltip' diff --git a/generators/components/src/templates/tooltip/styles.css.ts.hbs b/generators/components/src/templates/tooltip/styles.css.ts.hbs deleted file mode 100644 index 24fceee4a..000000000 --- a/generators/components/src/templates/tooltip/styles.css.ts.hbs +++ /dev/null @@ -1,17 +0,0 @@ -import { style } from '@vanilla-extract/css' - -export const baseContainerStyles = style({ - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - minWidth: 30, - minHeight: 32, - padding: '8px 12px', - margin: 0, - color: 'rgba(255, 255, 255, 1)', - wordWrap: 'break-word', - backgroundColor: 'rgba(0, 0, 0, 0.75)', - borderRadius: '8px', - boxShadow: '0px 2px 24px rgba(0, 0, 0, 0.15)', - zIndex: 1000, -}) From 70e11c2195cf0042addbc472766290b6dfa2cac7 Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Fri, 6 Nov 2026 11:07:13 +0300 Subject: [PATCH 04/37] chore(tooltip): format --- ui-parts/tooltip/src/arrow/styles/shape/variants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ui-parts/tooltip/src/arrow/styles/shape/variants.ts b/ui-parts/tooltip/src/arrow/styles/shape/variants.ts index ab49003a0..8b24b0d61 100644 --- a/ui-parts/tooltip/src/arrow/styles/shape/variants.ts +++ b/ui-parts/tooltip/src/arrow/styles/shape/variants.ts @@ -1,7 +1,6 @@ import type { ArrowShape } from './interfaces.js' import { DEFAULT_ARROW_HEIGHT } from './constants.js' - import { DEFAULT_ARROW_WIDTH } from './constants.js' export const arrowShapes: Record<'default', ArrowShape> = { From 8daf5bbfa904fac7dafcad30df28d6dfa7d3d096 Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Fri, 6 Nov 2026 11:10:43 +0300 Subject: [PATCH 05/37] fix(tooltip): wrap long unbroken text --- ui-parts/tooltip/src/text/component.tsx | 3 ++- ui-parts/tooltip/src/text/styles/base.css.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 ui-parts/tooltip/src/text/styles/base.css.ts diff --git a/ui-parts/tooltip/src/text/component.tsx b/ui-parts/tooltip/src/text/component.tsx index 7f985c082..3edeec682 100644 --- a/ui-parts/tooltip/src/text/component.tsx +++ b/ui-parts/tooltip/src/text/component.tsx @@ -3,9 +3,10 @@ import type { ReactNode } from 'react' import type { TextShape } from './styles/shape/interfaces.js' import { textAppearanceStyles } from './styles/appearance/styles.css.js' +import { textBaseStyles } from './styles/base.css.js' export const Text = ({ text, shape }: { text: string; shape: TextShape }): ReactNode => ( - + {text} ) diff --git a/ui-parts/tooltip/src/text/styles/base.css.ts b/ui-parts/tooltip/src/text/styles/base.css.ts new file mode 100644 index 000000000..3fd749c3f --- /dev/null +++ b/ui-parts/tooltip/src/text/styles/base.css.ts @@ -0,0 +1,3 @@ +import { style } from '@vanilla-extract/css' + +export const textBaseStyles = style({ overflowWrap: 'break-word' }) From 72e20dee2ce60a3ac0f8f2d6d402c1096507d81a Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Wed, 18 Nov 2026 15:49:13 +0300 Subject: [PATCH 06/37] refactor(progress): share theme shadow tokens --- .../circle/box/styles/appearance/variants.ts | 14 ++------- .../src/linear/styles/appearance/constants.ts | 4 --- .../src/linear/styles/appearance/variants.ts | 29 ++++++------------- ui-parts/progress/src/shadow.ts | 11 +++++++ 4 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 ui-parts/progress/src/linear/styles/appearance/constants.ts create mode 100644 ui-parts/progress/src/shadow.ts diff --git a/ui-parts/progress/src/circle/box/styles/appearance/variants.ts b/ui-parts/progress/src/circle/box/styles/appearance/variants.ts index f826c6989..c05a9739b 100644 --- a/ui-parts/progress/src/circle/box/styles/appearance/variants.ts +++ b/ui-parts/progress/src/circle/box/styles/appearance/variants.ts @@ -2,23 +2,15 @@ import type { Theme } from '@atls-ui/theme' import type { BoxAppearance } from './interfaces.js' -import { shadowOffsets } from '@atls-ui/theme/tokens' -import { shadowBlurs } from '@atls-ui/theme/tokens' -import { shadowSpreads } from '@atls-ui/theme/tokens' - -const boxShadow = (theme: Theme): BoxAppearance['shadow'] => - [ - `${shadowOffsets.none} ${shadowOffsets.none} ${shadowBlurs.xs6} ${shadowSpreads.xs2} ${theme.colors.action.subtle}`, - `${shadowOffsets.none} ${shadowOffsets.none} ${shadowBlurs.xs7} ${shadowSpreads.xs3} ${theme.colors.elevation.sm}`, - ].join(', ') +import { progressShadow } from '../../../../shadow.js' export const boxAppearances = { primary: (theme: Theme): BoxAppearance => ({ backgroundColor: theme.colors.surface.base, - shadow: boxShadow(theme), + shadow: progressShadow(theme), }), secondary: (theme: Theme): BoxAppearance => ({ backgroundColor: theme.colors.text.secondary, - shadow: boxShadow(theme), + shadow: progressShadow(theme), }), } diff --git a/ui-parts/progress/src/linear/styles/appearance/constants.ts b/ui-parts/progress/src/linear/styles/appearance/constants.ts deleted file mode 100644 index 1f18e7579..000000000 --- a/ui-parts/progress/src/linear/styles/appearance/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const LINEAR_SHADOW_ACTION_BLUR = '0.5px' -export const LINEAR_SHADOW_ACTION_SPREAD = '0.3px' -export const LINEAR_SHADOW_ELEVATION_BLUR = '0.2px' -export const LINEAR_SHADOW_ELEVATION_SPREAD = '0.2px' diff --git a/ui-parts/progress/src/linear/styles/appearance/variants.ts b/ui-parts/progress/src/linear/styles/appearance/variants.ts index 72f5abc81..e852f7eac 100644 --- a/ui-parts/progress/src/linear/styles/appearance/variants.ts +++ b/ui-parts/progress/src/linear/styles/appearance/variants.ts @@ -1,29 +1,18 @@ -import type { Theme } from '@atls-ui/theme' +import type { Theme } from '@atls-ui/theme' -import type { LinearProgressAppearance } from './interfaces.js' +import type { LinearProgressAppearance } from './interfaces.js' -import { shadowOffsets } from '@atls-ui/theme/tokens' - -import { LINEAR_SHADOW_ACTION_BLUR } from './constants.js' -import { LINEAR_SHADOW_ACTION_SPREAD } from './constants.js' -import { LINEAR_SHADOW_ELEVATION_BLUR } from './constants.js' -import { LINEAR_SHADOW_ELEVATION_SPREAD } from './constants.js' -import { linearIndicatorAppearances } from '../../indicator/styles/appearance/variants.js' -import { linearTrackAppearances } from '../../track/styles/appearance/variants.js' - -const boxShadow = (theme: Theme): string => - [ - `${shadowOffsets.none} ${shadowOffsets.none} ${LINEAR_SHADOW_ACTION_BLUR} ${LINEAR_SHADOW_ACTION_SPREAD} ${theme.colors.action.subtle}`, - `${shadowOffsets.none} ${shadowOffsets.none} ${LINEAR_SHADOW_ELEVATION_BLUR} ${LINEAR_SHADOW_ELEVATION_SPREAD} ${theme.colors.elevation.sm}`, - ].join(', ') +import { progressShadow } from '../../../shadow.js' +import { linearIndicatorAppearances } from '../../indicator/styles/appearance/variants.js' +import { linearTrackAppearances } from '../../track/styles/appearance/variants.js' export const linearProgressAppearances = { primary: (theme: Theme): LinearProgressAppearance => ({ - track: { ...linearTrackAppearances.primary(theme), boxShadow: boxShadow(theme) }, - indicator: { ...linearIndicatorAppearances.primary(theme), boxShadow: boxShadow(theme) }, + track: { ...linearTrackAppearances.primary(theme), boxShadow: progressShadow(theme) }, + indicator: { ...linearIndicatorAppearances.primary(theme), boxShadow: progressShadow(theme) }, }), secondary: (theme: Theme): LinearProgressAppearance => ({ - track: { ...linearTrackAppearances.secondary(theme), boxShadow: boxShadow(theme) }, - indicator: { ...linearIndicatorAppearances.secondary(theme), boxShadow: boxShadow(theme) }, + track: { ...linearTrackAppearances.secondary(theme), boxShadow: progressShadow(theme) }, + indicator: { ...linearIndicatorAppearances.secondary(theme), boxShadow: progressShadow(theme) }, }), } diff --git a/ui-parts/progress/src/shadow.ts b/ui-parts/progress/src/shadow.ts new file mode 100644 index 000000000..e3292d121 --- /dev/null +++ b/ui-parts/progress/src/shadow.ts @@ -0,0 +1,11 @@ +import type { Theme } from '@atls-ui/theme' + +import { shadowOffsets } from '@atls-ui/theme/tokens' +import { shadowBlurs } from '@atls-ui/theme/tokens' +import { shadowSpreads } from '@atls-ui/theme/tokens' + +export const progressShadow = (theme: Theme): string => + [ + `${shadowOffsets.none} ${shadowOffsets.none} ${shadowBlurs.xs6} ${shadowSpreads.xs2} ${theme.colors.action.subtle}`, + `${shadowOffsets.none} ${shadowOffsets.none} ${shadowBlurs.xs7} ${shadowSpreads.xs3} ${theme.colors.elevation.sm}`, + ].join(', ') From b9ea605befba1f4043134db14ca13ea3777c06bc Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Wed, 18 Nov 2026 15:49:25 +0300 Subject: [PATCH 07/37] refactor(progress): reserve percentage label space in CSS --- ui-parts/progress/src/circle/label/component.tsx | 14 +++++--------- .../progress/src/circle/label/styles/base.css.ts | 4 +++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ui-parts/progress/src/circle/label/component.tsx b/ui-parts/progress/src/circle/label/component.tsx index 39c92f651..d55e2e615 100644 --- a/ui-parts/progress/src/circle/label/component.tsx +++ b/ui-parts/progress/src/circle/label/component.tsx @@ -1,12 +1,11 @@ -import type { ReactNode } from 'react' +import type { ReactNode } from 'react' -import type { LabelShape } from './styles/shape/interfaces.js' +import type { LabelShape } from './styles/shape/interfaces.js' -import { useTheme } from '@atls-ui-parts/theme' +import { useTheme } from '@atls-ui-parts/theme' -import { labelStyles } from './styles/base.css.js' -import { labelReserveStyles } from './styles/base.css.js' -import { labelValueStyles } from './styles/base.css.js' +import { labelStyles } from './styles/base.css.js' +import { labelValueStyles } from './styles/base.css.js' export const Label = ({ value, @@ -22,9 +21,6 @@ export const Label = ({ typeof shape.typography === 'function' ? shape.typography(theme) : shape.typography return ( - {value === undefined ? null : `${Math.round(value)}%`} diff --git a/ui-parts/progress/src/circle/label/styles/base.css.ts b/ui-parts/progress/src/circle/label/styles/base.css.ts index 8f9cf8c0a..132e5c773 100644 --- a/ui-parts/progress/src/circle/label/styles/base.css.ts +++ b/ui-parts/progress/src/circle/label/styles/base.css.ts @@ -4,6 +4,8 @@ export const labelStyles = style({ display: 'inline-grid', whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums', + selectors: { + '&::before': { content: '"100%"', gridArea: '1 / 1', visibility: 'hidden' }, + }, }) -export const labelReserveStyles = style({ gridArea: '1 / 1', visibility: 'hidden' }) export const labelValueStyles = style({ gridArea: '1 / 1', textAlign: 'center' }) From 8b037636b5860715ea26e533bd882ebc3eec17db Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Wed, 18 Nov 2026 15:49:36 +0300 Subject: [PATCH 08/37] refactor(progress): reuse the default circle box shape --- .../src/circle/box/styles/shape/variants.ts | 37 +++---------------- .../src/circle/styles/shape/variants.ts | 14 +++---- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/ui-parts/progress/src/circle/box/styles/shape/variants.ts b/ui-parts/progress/src/circle/box/styles/shape/variants.ts index 15d96fe55..98b8c2003 100644 --- a/ui-parts/progress/src/circle/box/styles/shape/variants.ts +++ b/ui-parts/progress/src/circle/box/styles/shape/variants.ts @@ -3,35 +3,8 @@ import type { BoxShape } from './interfaces.js' import { radii } from '@atls-ui/theme/tokens' import { spacing } from '@atls-ui/theme/tokens' -export const boxShapes = { - xs2: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, - xs: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, - sm: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, - md: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, - lg: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, - xl: { - paddingInline: spacing.component.none, - paddingBlock: spacing.component.none, - radius: radii.full, - }, -} satisfies Record +export const boxShape: BoxShape = { + paddingInline: spacing.component.none, + paddingBlock: spacing.component.none, + radius: radii.full, +} diff --git a/ui-parts/progress/src/circle/styles/shape/variants.ts b/ui-parts/progress/src/circle/styles/shape/variants.ts index 09fd98688..e25c1caf1 100644 --- a/ui-parts/progress/src/circle/styles/shape/variants.ts +++ b/ui-parts/progress/src/circle/styles/shape/variants.ts @@ -1,6 +1,6 @@ import type { CircleProgressShape } from './interfaces.js' -import { boxShapes } from '../../box/styles/shape/variants.js' +import { boxShape } from '../../box/styles/shape/variants.js' import { containerShapes } from '../../container/styles/shape/variants.js' import { indicatorShapes } from '../../indicator/styles/shape/variants.js' import { labelShapes } from '../../label/styles/shape/variants.js' @@ -11,37 +11,37 @@ export const circleProgressShapes: Record< > = { xs2: { container: containerShapes.xs2, - box: boxShapes.xs2, + box: { ...boxShape }, indicator: indicatorShapes.xs2, label: labelShapes.xs2, }, xs: { container: containerShapes.xs, - box: boxShapes.xs, + box: { ...boxShape }, indicator: indicatorShapes.xs, label: labelShapes.xs, }, sm: { container: containerShapes.sm, - box: boxShapes.sm, + box: { ...boxShape }, indicator: indicatorShapes.sm, label: labelShapes.sm, }, md: { container: containerShapes.md, - box: boxShapes.md, + box: { ...boxShape }, indicator: indicatorShapes.md, label: labelShapes.md, }, lg: { container: containerShapes.lg, - box: boxShapes.lg, + box: { ...boxShape }, indicator: indicatorShapes.lg, label: labelShapes.lg, }, xl: { container: containerShapes.xl, - box: boxShapes.xl, + box: { ...boxShape }, indicator: indicatorShapes.xl, label: labelShapes.xl, }, From 0ccdd11d90ce7eba4180a6d8f947fdb66953fa44 Mon Sep 17 00:00:00 2001 From: Arina Gazhina Date: Wed, 18 Nov 2026 15:50:54 +0300 Subject: [PATCH 09/37] refactor(progress): render circle segments on a shared SVG track --- .../progress/src/circle/box/component.tsx | 25 ++++--- .../src/circle/box/styles/base.css.ts | 42 +++++++++-- .../circle/box/styles/shape/variables.css.ts | 8 +++ .../src/circle/box/styles/shape/variants.ts | 4 +- ui-parts/progress/src/circle/component.tsx | 44 +++++------- .../src/circle/container/styles/base.css.ts | 5 +- .../indicator/animation/useAnimation.ts | 2 +- .../src/circle/indicator/component.tsx | 69 ++++--------------- .../indicator/styles/shape/interfaces.ts | 4 +- .../src/circle/styles/shape/constants.ts | 3 - .../src/circle/styles/shape/interfaces.ts | 13 ---- .../src/circle/styles/shape/resolve.ts | 60 ---------------- .../progress/src/circle/track/component.tsx | 56 ++++++++++----- .../src/circle/track/styles/track.css.ts | 45 ++++++++++++ .../src/circle/track/styles/variables.css.ts | 4 ++ 15 files changed, 190 insertions(+), 194 deletions(-) create mode 100644 ui-parts/progress/src/circle/box/styles/shape/variables.css.ts delete mode 100644 ui-parts/progress/src/circle/styles/shape/constants.ts delete mode 100644 ui-parts/progress/src/circle/styles/shape/resolve.ts create mode 100644 ui-parts/progress/src/circle/track/styles/track.css.ts create mode 100644 ui-parts/progress/src/circle/track/styles/variables.css.ts diff --git a/ui-parts/progress/src/circle/box/component.tsx b/ui-parts/progress/src/circle/box/component.tsx index e87ca3f46..ce85272d5 100644 --- a/ui-parts/progress/src/circle/box/component.tsx +++ b/ui-parts/progress/src/circle/box/component.tsx @@ -3,27 +3,34 @@ import type { ReactNode } from 'react' import type { BoxAppearance } from './styles/appearance/interfaces.js' import type { BoxShape } from './styles/shape/interfaces.js' +import { assignInlineVars } from '@vanilla-extract/dynamic' + import { boxStyles } from './styles/base.css.js' +import { surfaceStyles } from './styles/base.css.js' +import { boxBackground } from './styles/base.css.js' +import { boxShadow } from './styles/base.css.js' export const Box = ({ - children, shape, appearance, + children, }: { - children: ReactNode shape: BoxShape appearance: BoxAppearance + children: ReactNode }): ReactNode => (
+ ) diff --git a/ui-parts/progress/src/circle/box/styles/base.css.ts b/ui-parts/progress/src/circle/box/styles/base.css.ts index 94bdf78b0..70e4aecdd 100644 --- a/ui-parts/progress/src/circle/box/styles/base.css.ts +++ b/ui-parts/progress/src/circle/box/styles/base.css.ts @@ -1,11 +1,43 @@ -import { style } from '@vanilla-extract/css' +import { createVar } from '@vanilla-extract/css' +import { style } from '@vanilla-extract/css' +import { boxRadius } from './shape/variables.css.js' +import { radiusInput } from './shape/variables.css.js' +export const boxBackground = createVar() +export const boxShadow = createVar() +const radius = `min(${boxRadius}, 50%) / min(${boxRadius}, 50%)` export const boxStyles = style({ + gridArea: '1 / 1', position: 'relative', - zIndex: 0, - boxSizing: 'border-box', - minWidth: 0, - minHeight: 0, + isolation: 'isolate', display: 'grid', placeItems: 'center', + minWidth: 0, + minHeight: 0, + boxSizing: 'border-box', +}) +export const surfaceStyles = style({ + position: 'absolute', + inset: 0, + containerType: 'size', + zIndex: -1, + pointerEvents: 'none', + selectors: { + '&::before': { + content: '""', + position: 'absolute', + inset: 0, + vars: { [boxRadius]: radiusInput }, + borderRadius: radius, + boxShadow, + }, + '&::after': { + content: '""', + position: 'absolute', + inset: 0, + vars: { [boxRadius]: radiusInput }, + clipPath: `inset(0 round ${radius})`, + backgroundColor: boxBackground, + }, + }, }) diff --git a/ui-parts/progress/src/circle/box/styles/shape/variables.css.ts b/ui-parts/progress/src/circle/box/styles/shape/variables.css.ts new file mode 100644 index 000000000..3dae5399e --- /dev/null +++ b/ui-parts/progress/src/circle/box/styles/shape/variables.css.ts @@ -0,0 +1,8 @@ +import { createVar } from '@vanilla-extract/css' + +export const radiusInput = createVar() +export const boxRadius = createVar({ + syntax: '', + inherits: true, + initialValue: '0px', +}) diff --git a/ui-parts/progress/src/circle/box/styles/shape/variants.ts b/ui-parts/progress/src/circle/box/styles/shape/variants.ts index 98b8c2003..738307373 100644 --- a/ui-parts/progress/src/circle/box/styles/shape/variants.ts +++ b/ui-parts/progress/src/circle/box/styles/shape/variants.ts @@ -3,8 +3,10 @@ import type { BoxShape } from './interfaces.js' import { radii } from '@atls-ui/theme/tokens' import { spacing } from '@atls-ui/theme/tokens' +const FULL_RADIUS = `min(${radii.full}, 50cqmin)` + export const boxShape: BoxShape = { paddingInline: spacing.component.none, paddingBlock: spacing.component.none, - radius: radii.full, + radius: FULL_RADIUS, } diff --git a/ui-parts/progress/src/circle/component.tsx b/ui-parts/progress/src/circle/component.tsx index 135e37fe1..b9fd5c46d 100644 --- a/ui-parts/progress/src/circle/component.tsx +++ b/ui-parts/progress/src/circle/component.tsx @@ -2,18 +2,23 @@ import type { ReactNode } from 'react' import type { CircleProgressProps } from './interfaces.js' +import { assignInlineVars } from '@vanilla-extract/dynamic' +import { clsx } from 'clsx' + import { useTheme } from '@atls-ui-parts/theme' import { Box } from './box/component.js' import { PROGRESS_MAX } from './constants.js' -import { Indicator } from './indicator/component.js' +import { DEFAULT_INDICATOR_OVERLAP } from './indicator/styles/shape/constants.js' import { Label } from './label/component.js' import { Track } from './track/component.js' +import { radiusInput } from './box/styles/shape/variables.css.js' import { containerStyles } from './container/styles/base.css.js' import { circleProgressAnimations } from './indicator/animation/variants.js' import { circleProgressAppearances } from './styles/appearance/variants.js' -import { resolveShape } from './styles/shape/resolve.js' import { circleProgressShapes } from './styles/shape/variants.js' +import { indicatorOverlap } from './track/styles/variables.css.js' +import { strokeWidth } from './track/styles/variables.css.js' export const CircleProgress = ({ value, @@ -32,7 +37,7 @@ export const CircleProgress = ({ value === undefined || !Number.isFinite(value) ? undefined : Math.max(0, Math.min(value, PROGRESS_MAX)) - const { padding, paintPadding, strokeWidth, contour } = resolveShape(shape) + const { strokeWidth: thickness, overlap = DEFAULT_INDICATOR_OVERLAP } = shape.indicator return (
- + {children ?? diff --git a/ui-parts/progress/src/circle/container/styles/base.css.ts b/ui-parts/progress/src/circle/container/styles/base.css.ts index 92a381924..04a56977d 100644 --- a/ui-parts/progress/src/circle/container/styles/base.css.ts +++ b/ui-parts/progress/src/circle/container/styles/base.css.ts @@ -1,8 +1,11 @@ -import { style } from '@vanilla-extract/css' +import { style } from '@vanilla-extract/css' + +import { strokeWidth } from '../../track/styles/variables.css.js' export const containerStyles = style({ position: 'relative', display: 'inline-grid', boxSizing: 'border-box', verticalAlign: 'top', + padding: `calc(${strokeWidth} / 2)`, }) diff --git a/ui-parts/progress/src/circle/indicator/animation/useAnimation.ts b/ui-parts/progress/src/circle/indicator/animation/useAnimation.ts index fd74c1b4a..edca0dab1 100644 --- a/ui-parts/progress/src/circle/indicator/animation/useAnimation.ts +++ b/ui-parts/progress/src/circle/indicator/animation/useAnimation.ts @@ -22,7 +22,7 @@ export const useAnimation = ( Number.parseFloat(animation.duration) * (animation.duration.endsWith('ms') ? 1 : MILLISECONDS_PER_SECOND) const motion = view.matchMedia('(prefers-reduced-motion: reduce)') - const players = Array.from(element.querySelectorAll('rect')).map((segment, index) => + const players = Array.from(element.children).map((segment, index) => segment.animate( getSegmentKeyframes( animation.segments[index].frames, diff --git a/ui-parts/progress/src/circle/indicator/component.tsx b/ui-parts/progress/src/circle/indicator/component.tsx index b81351ee2..aab2e38fd 100644 --- a/ui-parts/progress/src/circle/indicator/component.tsx +++ b/ui-parts/progress/src/circle/indicator/component.tsx @@ -1,13 +1,9 @@ import type { ReactNode } from 'react' -import type { ContourStyles } from '../styles/shape/interfaces.js' import type { CircleProgressAnimation } from './animation/interfaces.js' -import type { IndicatorAppearance } from './styles/appearance/interfaces.js' -import type { IndicatorShape } from './styles/shape/interfaces.js' import { assignInlineVars } from '@vanilla-extract/dynamic' import { clsx } from 'clsx' -import { useId } from 'react' import { useRef } from 'react' import { PROGRESS_MAX } from '../constants.js' @@ -17,65 +13,30 @@ import { segmentStyles } from './styles/base.css.js' import { segmentLength } from './styles/base.css.js' export const Indicator = ({ - contour, - strokeWidth, - appearance, + href, value, animation, }: { - contour: ContourStyles - strokeWidth: IndicatorShape['strokeWidth'] - appearance: IndicatorAppearance + href: string value?: number animation: CircleProgressAnimation }): ReactNode => { - const maskId = useId() const maskRef = useRef(null) useAnimation(maskRef, value === undefined ? animation : undefined) const segments = value === undefined ? animation.segments : [{ frames: [] }] - return ( - <> - - - - - {segments.map((_, index) => ( - - ))} - - - - -
- + + {segments.map((_, index) => ( + + ))} + ) } diff --git a/ui-parts/progress/src/circle/indicator/styles/shape/interfaces.ts b/ui-parts/progress/src/circle/indicator/styles/shape/interfaces.ts index 44233916d..6147443ed 100644 --- a/ui-parts/progress/src/circle/indicator/styles/shape/interfaces.ts +++ b/ui-parts/progress/src/circle/indicator/styles/shape/interfaces.ts @@ -1,6 +1,4 @@ -import type { CSSProperties } from 'react' - export interface IndicatorShape { overlap?: number - strokeWidth: NonNullable + strokeWidth: number | '0' | `${number}px` } diff --git a/ui-parts/progress/src/circle/styles/shape/constants.ts b/ui-parts/progress/src/circle/styles/shape/constants.ts deleted file mode 100644 index 13f05aca6..000000000 --- a/ui-parts/progress/src/circle/styles/shape/constants.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const PERCENTAGE_SCALE = 100 -export const MAX_RADIUS_RATIO = 0.5 -export const SVG_DIAGONAL_RATIO = Math.SQRT1_2 diff --git a/ui-parts/progress/src/circle/styles/shape/interfaces.ts b/ui-parts/progress/src/circle/styles/shape/interfaces.ts index 322254eee..ea129ff56 100644 --- a/ui-parts/progress/src/circle/styles/shape/interfaces.ts +++ b/ui-parts/progress/src/circle/styles/shape/interfaces.ts @@ -1,5 +1,3 @@ -import type { SVGAttributes } from 'react' - import type { BoxShape } from '../../box/styles/shape/interfaces.js' import type { ContainerShape } from '../../container/styles/shape/interfaces.js' import type { IndicatorShape } from '../../indicator/styles/shape/interfaces.js' @@ -11,14 +9,3 @@ export interface CircleProgressShape { indicator: IndicatorShape label: LabelShape } -export type ContourStyles = Pick< - SVGAttributes, - 'height' | 'rx' | 'ry' | 'width' | 'x' | 'y' -> - -export interface ResolvedCircleProgressShape { - padding: string - paintPadding: string - strokeWidth: string - contour: ContourStyles -} diff --git a/ui-parts/progress/src/circle/styles/shape/resolve.ts b/ui-parts/progress/src/circle/styles/shape/resolve.ts deleted file mode 100644 index 08716dc85..000000000 --- a/ui-parts/progress/src/circle/styles/shape/resolve.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { CircleProgressShape } from './interfaces.js' -import type { ResolvedCircleProgressShape } from './interfaces.js' - -import { spacing } from '@atls-ui/theme/tokens' - -import { PAINT_PIXEL_SIZE } from '../../constants.js' -import { STROKE_CENTER_RATIO } from '../../constants.js' -import { DEFAULT_INDICATOR_OVERLAP } from '../../indicator/styles/shape/constants.js' -import { MAX_RADIUS_RATIO } from './constants.js' -import { PERCENTAGE_SCALE } from './constants.js' -import { SVG_DIAGONAL_RATIO } from './constants.js' - -const percentage = (value: string): number | undefined => { - const normalized = value.trim() - if (!normalized.endsWith('%')) return undefined - const number = Number(normalized.slice(0, -1)) - return Number.isFinite(number) ? number / PERCENTAGE_SCALE : undefined -} - -const length = (value: number | string): string => - typeof value === 'number' || value.trim() === '0' ? `${Number(value)}px` : value - -export const resolveShape = (shape: CircleProgressShape): ResolvedCircleProgressShape => { - const { overlap = DEFAULT_INDICATOR_OVERLAP } = shape.indicator - const rawStroke = length(shape.indicator.strokeWidth) - const strokeRatio = percentage(rawStroke) - const strokeWidth = - strokeRatio === undefined - ? rawStroke - : `calc(hypot(100cqw, 100cqh) * ${strokeRatio * SVG_DIAGONAL_RATIO})` - const containerPadding = shape.container?.padding - const padding = length( - containerPadding ?? - (strokeRatio === undefined ? `calc(${rawStroke} / 2)` : spacing.component.none) - ) - const offset = `calc(${strokeWidth} * (${STROKE_CENTER_RATIO} - ${overlap}))` - const inset = `calc(${padding} - ${offset})` - const paintPadding = `calc(${strokeWidth} + ${PAINT_PIXEL_SIZE})` - const width = `calc(100cqw - 2 * ${inset})` - const height = `calc(100cqh - 2 * ${inset})` - const radiusRatio = percentage(shape.box.radius) - const radius = `min(max(0px, calc(${length(shape.box.radius)} + ${offset})), ${width} / 2, ${height} / 2)` - const axisRadius = (axis: string): string => - radiusRatio === undefined - ? radius - : `max(0px, calc((100${axis} - 2 * ${padding}) * ${Math.min(radiusRatio, MAX_RADIUS_RATIO)} + ${offset}))` - return { - padding, - paintPadding, - strokeWidth, - contour: { - x: `calc(${inset} + ${paintPadding})`, - y: `calc(${inset} + ${paintPadding})`, - width, - height, - rx: axisRadius('cqw'), - ry: axisRadius('cqh'), - }, - } -} diff --git a/ui-parts/progress/src/circle/track/component.tsx b/ui-parts/progress/src/circle/track/component.tsx index 1eac846d0..c917507e8 100644 --- a/ui-parts/progress/src/circle/track/component.tsx +++ b/ui-parts/progress/src/circle/track/component.tsx @@ -1,23 +1,41 @@ -import type { ReactNode } from 'react' +import type { ReactNode } from 'react' -import type { IndicatorShape } from '../indicator/styles/shape/interfaces.js' -import type { ContourStyles } from '../styles/shape/interfaces.js' +import type { CircleProgressAnimation } from '../indicator/animation/interfaces.js' +import type { CircleProgressAppearance } from '../styles/appearance/interfaces.js' + +import { useId } from 'react' + +import { Indicator } from '../indicator/component.js' +import { lineStyles } from './styles/track.css.js' +import { layerStyles } from './styles/track.css.js' +import { trackStyles } from './styles/track.css.js' export const Track = ({ - contour, - strokeWidth, - color, + appearance, + value, + animation, }: { - contour: ContourStyles - strokeWidth: IndicatorShape['strokeWidth'] - color: string -}): ReactNode => ( - -) + appearance: CircleProgressAppearance + value?: number + animation: CircleProgressAnimation +}): ReactNode => { + const id = useId() + const maskId = useId() + return ( +