@propellerads/header 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import v from "dayjs/plugin/utc";
8
8
  import './index.css';//#region src/balance.tsx
9
9
  var y = (e, t = 2) => e.toFixed(t).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"), b = ({ value: e, decimals: t }) => /* @__PURE__ */ m("span", { children: [/* @__PURE__ */ p("span", {
10
10
  className: "header__currency",
11
- children: "USD"
11
+ children: "$"
12
12
  }), y(e, t)] }), x = ({ day: e }) => /* @__PURE__ */ m(c, { children: [/* @__PURE__ */ p(d, {
13
13
  render: /* @__PURE__ */ p("span", {}),
14
14
  className: "header__bar",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/balance.tsx","../src/cn.ts","../src/context.ts","../src/item.tsx","../src/time.tsx","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {Position, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from '@propellerads/smart-tooltip';\nimport type {DayEarned, HeaderBalanceProps} from './types';\n\n/* @propellerads/currency's formatting, inlined: the package still draws its\n code with styled-components, and the header has no other use for it. */\nconst formatMoney = (value: number, decimals = 2) => value.toFixed(decimals).replace(/(\\d)(?=(\\d{3})+\\.)/g, '$1,');\n\nconst Money = ({value, decimals}: {value: number; decimals?: number}) => (\n <span>\n <span className=\"header__currency\">USD</span>\n {formatMoney(value, decimals)}\n </span>\n);\n\nconst Bar = ({day}: {day: DayEarned}) => (\n <Tooltip>\n <TooltipTrigger render={<span />} className=\"header__bar\">\n <span className=\"header__bar-value\" style={{height: day.percentage > 1 ? `${day.percentage}%` : '1px'}} />\n </TooltipTrigger>\n <TooltipContent side={Position.Bottom}>\n {day.date} — <Money value={day.value} />\n </TooltipContent>\n </Tooltip>\n);\n\n/**\n * The balance and, beside it, a bar per day. Each bar names its day in a\n * SmartTooltip; the tooltips share one provider with no delay, so running the\n * pointer along the bars reads them one after another the way v7's labels did.\n */\nconst HeaderBalance = ({balance, dailyEarned = []}: HeaderBalanceProps) => (\n <div className=\"header__balance\">\n <span className=\"header__balance-value\">\n <Money value={balance} />\n </span>\n\n {dailyEarned.length > 0 && (\n <TooltipProvider delay={0} closeDelay={0}>\n <span className=\"header__chart\">\n {dailyEarned.map((day, index) => (\n <Bar key={index} day={day} />\n ))}\n </span>\n </TooltipProvider>\n )}\n </div>\n);\n\nexport {HeaderBalance};\n","import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the header\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import {createContext, type RefObject, useContext} from 'react';\nimport type {ThemeName} from './types';\n\ntype HeaderContextValue = {\n /** The bar itself: on a phone a dropdown hangs off it rather than off its item. */\n barRef: RefObject<HTMLElement | null>;\n theme: ThemeName;\n};\n\nconst HeaderContext = createContext<HeaderContextValue | null>(null);\n\nconst useHeader = () => useContext(HeaderContext);\n\nexport {HeaderContext, useHeader};\n","import {Popover} from '@base-ui-components/react/popover';\nimport {useState, useSyncExternalStore} from 'react';\nimport {cn} from './cn';\nimport {useHeader} from './context';\nimport type {HeaderDropdownListProps, HeaderDropdownProps, HeaderItemProps} from './types';\n\n/* Below the tablet breakpoint a dropdown spans the bar rather than standing\n under its item, as v7's did. The number repeats --breakpoint-tablet: a media\n query cannot read a custom property. */\nconst MOBILE_QUERY = '(max-width: 768px)';\n\nconst subscribeToMobile = (onChange: () => void) => {\n const query = window.matchMedia(MOBILE_QUERY);\n query.addEventListener('change', onChange);\n return () => query.removeEventListener('change', onChange);\n};\n\nconst useIsMobile = (): boolean =>\n useSyncExternalStore(\n subscribeToMobile,\n () => window.matchMedia(MOBILE_QUERY).matches,\n () => false,\n );\n\nconst Content = ({icon, title, component}: Pick<HeaderItemProps, 'icon' | 'title' | 'component'>) => (\n <>\n {icon}\n {title !== undefined && <span className=\"header__item-title\">{title}</span>}\n {component}\n </>\n);\n\n/**\n * One control of the bar: a plain button with `onClick`, a dropdown trigger\n * with `children`, or both missing — then it is a button that does nothing,\n * which a product wraps to hang its own behaviour on (Beamer does).\n *\n * The dropdown is shadcn's Popover on Base UI: it stands under the item, takes\n * the focus when it opens, gives it back to the item when it closes, and closes\n * on Escape and on a press outside. A click anywhere inside it closes it too,\n * as v7's did — a menu row has done its job once clicked. Content that has to\n * stay open under a click stops the event's propagation, which works the same\n * through the portal.\n */\nconst HeaderItem = ({\n id,\n className,\n children,\n onClick,\n component,\n icon,\n title,\n isRightDropdown = false,\n 'aria-label': ariaLabel,\n}: HeaderItemProps) => {\n const header = useHeader();\n const isMobile = useIsMobile();\n const [isOpen, setIsOpen] = useState(false);\n\n const content = <Content icon={icon} title={title} component={component} />;\n const hasDropdown = children !== undefined && children !== null && onClick === undefined;\n\n if (!hasDropdown) {\n return (\n <div id={id} className={cn('header__item', className)}>\n <button type=\"button\" className=\"header__item-button\" aria-label={ariaLabel} onClick={onClick}>\n {content}\n </button>\n </div>\n );\n }\n\n return (\n <div id={id} className={cn('header__item', className)}>\n <Popover.Root open={isOpen} onOpenChange={setIsOpen}>\n <Popover.Trigger className=\"header__item-button\" aria-label={ariaLabel}>\n {content}\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Positioner\n className={cn('header__positioner', `header-theme--${header?.theme ?? 'light'}`)}\n anchor={isMobile ? header?.barRef : undefined}\n side=\"bottom\"\n align={isRightDropdown || isMobile ? 'end' : 'start'}\n sideOffset={isMobile ? 0 : 4}\n collisionPadding={8}\n >\n <Popover.Popup\n className={cn('header__popup', isMobile && 'header__popup--wide')}\n onClick={() => setIsOpen(false)}\n >\n {children}\n </Popover.Popup>\n </Popover.Positioner>\n </Popover.Portal>\n </Popover.Root>\n </div>\n );\n};\n\n/** The pad of a dropdown. Its `id` is where products hang their overrides. */\nconst HeaderDropdown = ({id, className, children}: HeaderDropdownProps) => (\n <div id={id} className={cn('header__dropdown', className)}>\n {children}\n </div>\n);\n\n/** Rows of a menu: what is in a row fills it, so the whole row is the hit area. */\nconst HeaderDropdownList = ({items = []}: HeaderDropdownListProps) => (\n <div className=\"header__menu\">\n {items.map((item, index) => (\n // The rows are whatever the product passed and carry no identity of their own.\n <div key={index} className=\"header__menu-item\">\n {item}\n </div>\n ))}\n </div>\n);\n\nexport {HeaderDropdown, HeaderDropdownList, HeaderItem};\n","import {Position, Tooltip, TooltipContent, TooltipTrigger} from '@propellerads/smart-tooltip';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport {useEffect, useState} from 'react';\nimport type {HeaderTimeProps} from './types';\n\ndayjs.extend(utc);\n\n/* v7's arithmetic, kept as is: UTC−5 all year, with no daylight saving. */\nconst now = () => dayjs.utc().subtract(5, 'hour');\n\nconst defaultContent: NonNullable<HeaderTimeProps['tooltipContent']> = (date) =>\n `System time: ${date.format('HH:mm DD.MM')} (EST)`;\n\n/** The system time, in EST, with the date in a tooltip. */\nconst HeaderTime = ({tooltipContent = defaultContent}: HeaderTimeProps) => {\n const [time, setTime] = useState(now);\n\n useEffect(() => {\n const timer = setInterval(() => setTime(now()), 1000);\n\n return () => clearInterval(timer);\n }, []);\n\n return (\n <Tooltip>\n <TooltipTrigger render={<span />} className=\"header__time\">\n {`${time.format('HH:mm')} EST`}\n </TooltipTrigger>\n <TooltipContent side={Position.Bottom}>{tooltipContent(time)}</TooltipContent>\n </Tooltip>\n );\n};\n\nexport {HeaderTime};\n","import type {Dayjs} from 'dayjs';\nimport type {CSSProperties, ReactNode} from 'react';\n\n/**\n * What the bar is worn in.\n *\n * `light` is the page itself: the tokens' surface and text, so it turns over\n * with the theme the product writes on <html>. `dark` stays dark on a light\n * page as well — the dark theme's greys, scoped to the bar and its dropdowns.\n * `transparent` is `light` with the surface and the shadow taken away, for a\n * bar laid over a page that draws its own background.\n */\nexport const ThemeName = {\n Dark: 'dark',\n Light: 'light',\n Transparent: 'transparent',\n} as const;\nexport type ThemeName = (typeof ThemeName)[keyof typeof ThemeName];\n\nexport type HeaderProps = {\n /** The brand: a logo, a link home. */\n logo: ReactNode;\n /** Stands before the logo, usually an `Header.Item` that opens the sidebar. */\n sidebarButton?: ReactNode;\n /** The right-hand side: items, dividers, the balance, the time. */\n children: ReactNode;\n /** @default 'light' */\n theme?: ThemeName;\n /** @default 'header-container' — products find the bar by it. */\n id?: string;\n className?: string;\n style?: CSSProperties;\n /** @deprecated Use `style`. Kept for the products that still pass it. */\n customHeaderStyle?: CSSProperties;\n};\n\nexport type HeaderItemProps = {\n /** Lands on the item's wrapper. */\n id?: string;\n className?: string;\n /**\n * The dropdown, usually a `Header.Dropdown`. Clicking the item opens it,\n * clicking anything inside it closes it. Ignored when `onClick` is given.\n */\n children?: ReactNode;\n /** Makes the item a plain button: no dropdown opens. */\n onClick?: () => void;\n /** Free content of the button, after the icon and the title. */\n component?: ReactNode;\n icon?: ReactNode;\n title?: string;\n /** Aligns the dropdown to the item's right edge instead of its left. */\n isRightDropdown?: boolean;\n /** The button's accessible name, for an item that is only an icon. */\n 'aria-label'?: string;\n};\n\nexport type HeaderDropdownProps = {\n id?: string;\n className?: string;\n children: ReactNode;\n};\n\nexport type HeaderDropdownListProps = {\n /** One row each. A link or a button in a row fills the whole row. */\n items?: ReactNode[];\n};\n\nexport type DayEarned = {\n date: string;\n value: number;\n /** The bar's height, 0–100. Below 1 the bar is a hairline. */\n percentage: number;\n};\n\nexport type HeaderBalanceProps = {\n balance: number;\n /** A bar per day beside the balance, hidden below the tablet breakpoint. */\n dailyEarned?: DayEarned[];\n};\n\nexport type HeaderTimeProps = {\n /** What the tooltip says, given the current time in EST. */\n tooltipContent?: (ESTDate: Dayjs) => ReactNode;\n};\n","import {useMemo, useRef} from 'react';\nimport './header.css';\nimport {HeaderBalance} from './balance';\nimport {cn} from './cn';\nimport {HeaderContext} from './context';\nimport {HeaderDropdown, HeaderDropdownList, HeaderItem} from './item';\nimport {HeaderTime} from './time';\nimport {\n type DayEarned,\n type HeaderBalanceProps,\n type HeaderDropdownListProps,\n type HeaderDropdownProps,\n type HeaderItemProps,\n type HeaderProps,\n type HeaderTimeProps,\n ThemeName,\n} from './types';\n\n/**\n * v7 took a theme object and products wrote `theme={themes.dark}`. The object\n * is a name now, and `themes` maps each name onto itself, so that line keeps\n * working.\n *\n * @deprecated Pass `ThemeName.Dark` or `'dark'`.\n */\nconst themes: Record<ThemeName, ThemeName> = {\n [ThemeName.Dark]: ThemeName.Dark,\n [ThemeName.Light]: ThemeName.Light,\n [ThemeName.Transparent]: ThemeName.Transparent,\n};\n\n/* A product may still hand over a v7 theme object, a copy of one or one of\n its own; it gets the light bar rather than a broken one. */\nconst toThemeName = (theme: unknown): ThemeName =>\n Object.values(ThemeName).includes(theme as ThemeName) ? (theme as ThemeName) : ThemeName.Light;\n\nconst HeaderDivider = () => <span className=\"header__divider\" aria-hidden=\"true\" />;\n\nconst HeaderRoot = ({\n logo,\n sidebarButton,\n children,\n theme,\n id = 'header-container',\n className,\n style,\n customHeaderStyle,\n}: HeaderProps) => {\n const barRef = useRef<HTMLElement | null>(null);\n const themeName = toThemeName(theme);\n const context = useMemo(() => ({barRef, theme: themeName}), [themeName]);\n\n return (\n <HeaderContext.Provider value={context}>\n <header\n ref={barRef}\n id={id}\n className={cn('header', `header-theme--${themeName}`, className)}\n style={{...customHeaderStyle, ...style}}\n >\n <div className=\"header__brand\">\n {sidebarButton}\n {logo}\n </div>\n\n <div className=\"header__options\">{children}</div>\n </header>\n </HeaderContext.Provider>\n );\n};\n\ntype HeaderCompound = typeof HeaderRoot & {\n Item: typeof HeaderItem;\n Balance: typeof HeaderBalance;\n Time: typeof HeaderTime;\n Divider: typeof HeaderDivider;\n Dropdown: typeof HeaderDropdown;\n DropdownList: typeof HeaderDropdownList;\n};\n\nconst Header: HeaderCompound = Object.assign(HeaderRoot, {\n Item: HeaderItem,\n Balance: HeaderBalance,\n Time: HeaderTime,\n Divider: HeaderDivider,\n Dropdown: HeaderDropdown,\n DropdownList: HeaderDropdownList,\n});\n\nexport default Header;\nexport type {\n DayEarned,\n HeaderBalanceProps,\n HeaderDropdownListProps,\n HeaderDropdownProps,\n HeaderItemProps,\n HeaderProps,\n HeaderTimeProps,\n};\nexport {\n Header,\n HeaderBalance,\n HeaderDivider,\n HeaderDropdown,\n HeaderDropdownList,\n HeaderItem,\n HeaderTime,\n ThemeName,\n themes,\n};\n"],"mappings":";;;;;;;;AAKA,IAAM,KAAe,GAAe,IAAW,MAAM,EAAM,QAAQ,EAAS,CAAC,QAAQ,uBAAuB,MAAM,EAE5G,KAAS,EAAC,UAAO,kBACrB,kBAAC,QAAD,EAAA,UAAA,CACE,kBAAC,QAAD;CAAM,WAAU;WAAmB;CAAU,CAAA,EAC5C,EAAY,GAAO,EAAS,CACxB,EAAA,CAAA,EAGH,KAAO,EAAC,aACZ,kBAAC,GAAD,EAAA,UAAA,CACE,kBAAC,GAAD;CAAgB,QAAQ,kBAAC,QAAD,EAAQ,CAAA;CAAE,WAAU;WAC1C,kBAAC,QAAD;EAAM,WAAU;EAAoB,OAAO,EAAC,QAAQ,EAAI,aAAa,IAAI,GAAG,EAAI,WAAW,KAAK,OAAM;EAAI,CAAA;CAC3F,CAAA,EACjB,kBAAC,GAAD;CAAgB,MAAM,EAAS;WAA/B;EACG,EAAI;EAAK;EAAG,kBAAC,GAAD,EAAO,OAAO,EAAI,OAAS,CAAA;EACzB;GACT,EAAA,CAAA,EAQN,KAAiB,EAAC,YAAS,iBAAc,EAAE,OAC/C,kBAAC,OAAD;CAAK,WAAU;WAAf,CACE,kBAAC,QAAD;EAAM,WAAU;YACd,kBAAC,GAAD,EAAO,OAAO,GAAW,CAAA;EACpB,CAAA,EAEN,EAAY,SAAS,KACpB,kBAAC,GAAD;EAAiB,OAAO;EAAG,YAAY;YACrC,kBAAC,QAAD;GAAM,WAAU;aACb,EAAY,KAAK,GAAK,MACrB,k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AC5B,EAAU,cAAc,EAAU;CACpC,EAIK,KAAe,MACnB,OAAO,OAAO,EAAU,CAAC,SAAS,EAAmB,GAAI,IAAsB,EAAU,OAErF,UAAsB,kBAAC,QAAD;CAAM,WAAU;CAAkB,eAAY;CAAS,CAAA,EA4C7E,IAAyB,OAAO,QA1ClB,EAClB,SACA,kBACA,aACA,UACA,QAAK,oBACL,cACA,UACA,2BACiB;CACjB,IAAM,IAAS,EAA2B,KAAK,EACzC,IAAY,EAAY,EAAM,EAC9B,IAAU,SAAe;EAAC;EAAQ,OAAO;EAAU,GAAG,CAAC,EAAU,CAAC;CAExE,OACE,kBAAC,EAAc,UAAf;EAAwB,OAAO;YAC7B,kBAAC,UAAD;GACE,KAAK;GACD;GACJ,WAAW,EAAG,UAAU,iBAAiB,KAAa,EAAU;GAChE,OAAO;IAAC,GAAG;IAAmB,GAAG;IAAM;aAJzC,CAME,kBAAC,OAAD;IAAK,WAAU;cAAf,CACG,GACA,EACG;OAEN,kBAAC,OAAD;IAAK,WAAU;IAAmB;IAAe,CAAA,CAC1C;;EACc,CAAA;GAa4B;CACvD,MAAM;CACN,SAAS;CACT,MAAM;CACN,SAAS;CACT,UAAU;CACV,cAAc;CACf,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/balance.tsx","../src/cn.ts","../src/context.ts","../src/item.tsx","../src/time.tsx","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {Position, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from '@propellerads/smart-tooltip';\nimport type {DayEarned, HeaderBalanceProps} from './types';\n\n/* @propellerads/currency's formatting, inlined: the package still draws its\n code with styled-components, and the header has no other use for it. */\nconst formatMoney = (value: number, decimals = 2) => value.toFixed(decimals).replace(/(\\d)(?=(\\d{3})+\\.)/g, '$1,');\n\nconst Money = ({value, decimals}: {value: number; decimals?: number}) => (\n <span>\n <span className=\"header__currency\">$</span>\n {formatMoney(value, decimals)}\n </span>\n);\n\nconst Bar = ({day}: {day: DayEarned}) => (\n <Tooltip>\n <TooltipTrigger render={<span />} className=\"header__bar\">\n <span className=\"header__bar-value\" style={{height: day.percentage > 1 ? `${day.percentage}%` : '1px'}} />\n </TooltipTrigger>\n <TooltipContent side={Position.Bottom}>\n {day.date} — <Money value={day.value} />\n </TooltipContent>\n </Tooltip>\n);\n\n/**\n * The balance and, beside it, a bar per day. Each bar names its day in a\n * SmartTooltip; the tooltips share one provider with no delay, so running the\n * pointer along the bars reads them one after another the way v7's labels did.\n */\nconst HeaderBalance = ({balance, dailyEarned = []}: HeaderBalanceProps) => (\n <div className=\"header__balance\">\n <span className=\"header__balance-value\">\n <Money value={balance} />\n </span>\n\n {dailyEarned.length > 0 && (\n <TooltipProvider delay={0} closeDelay={0}>\n <span className=\"header__chart\">\n {dailyEarned.map((day, index) => (\n <Bar key={index} day={day} />\n ))}\n </span>\n </TooltipProvider>\n )}\n </div>\n);\n\nexport {HeaderBalance};\n","import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the header\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import {createContext, type RefObject, useContext} from 'react';\nimport type {ThemeName} from './types';\n\ntype HeaderContextValue = {\n /** The bar itself: on a phone a dropdown hangs off it rather than off its item. */\n barRef: RefObject<HTMLElement | null>;\n theme: ThemeName;\n};\n\nconst HeaderContext = createContext<HeaderContextValue | null>(null);\n\nconst useHeader = () => useContext(HeaderContext);\n\nexport {HeaderContext, useHeader};\n","import {Popover} from '@base-ui-components/react/popover';\nimport {useState, useSyncExternalStore} from 'react';\nimport {cn} from './cn';\nimport {useHeader} from './context';\nimport type {HeaderDropdownListProps, HeaderDropdownProps, HeaderItemProps} from './types';\n\n/* Below the tablet breakpoint a dropdown spans the bar rather than standing\n under its item, as v7's did. The number repeats --breakpoint-tablet: a media\n query cannot read a custom property. */\nconst MOBILE_QUERY = '(max-width: 768px)';\n\nconst subscribeToMobile = (onChange: () => void) => {\n const query = window.matchMedia(MOBILE_QUERY);\n query.addEventListener('change', onChange);\n return () => query.removeEventListener('change', onChange);\n};\n\nconst useIsMobile = (): boolean =>\n useSyncExternalStore(\n subscribeToMobile,\n () => window.matchMedia(MOBILE_QUERY).matches,\n () => false,\n );\n\nconst Content = ({icon, title, component}: Pick<HeaderItemProps, 'icon' | 'title' | 'component'>) => (\n <>\n {icon}\n {title !== undefined && <span className=\"header__item-title\">{title}</span>}\n {component}\n </>\n);\n\n/**\n * One control of the bar: a plain button with `onClick`, a dropdown trigger\n * with `children`, or both missing — then it is a button that does nothing,\n * which a product wraps to hang its own behaviour on (Beamer does).\n *\n * The dropdown is shadcn's Popover on Base UI: it stands under the item, takes\n * the focus when it opens, gives it back to the item when it closes, and closes\n * on Escape and on a press outside. A click anywhere inside it closes it too,\n * as v7's did — a menu row has done its job once clicked. Content that has to\n * stay open under a click stops the event's propagation, which works the same\n * through the portal.\n */\nconst HeaderItem = ({\n id,\n className,\n children,\n onClick,\n component,\n icon,\n title,\n isRightDropdown = false,\n 'aria-label': ariaLabel,\n}: HeaderItemProps) => {\n const header = useHeader();\n const isMobile = useIsMobile();\n const [isOpen, setIsOpen] = useState(false);\n\n const content = <Content icon={icon} title={title} component={component} />;\n const hasDropdown = children !== undefined && children !== null && onClick === undefined;\n\n if (!hasDropdown) {\n return (\n <div id={id} className={cn('header__item', className)}>\n <button type=\"button\" className=\"header__item-button\" aria-label={ariaLabel} onClick={onClick}>\n {content}\n </button>\n </div>\n );\n }\n\n return (\n <div id={id} className={cn('header__item', className)}>\n <Popover.Root open={isOpen} onOpenChange={setIsOpen}>\n <Popover.Trigger className=\"header__item-button\" aria-label={ariaLabel}>\n {content}\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Positioner\n className={cn('header__positioner', `header-theme--${header?.theme ?? 'light'}`)}\n anchor={isMobile ? header?.barRef : undefined}\n side=\"bottom\"\n align={isRightDropdown || isMobile ? 'end' : 'start'}\n sideOffset={isMobile ? 0 : 4}\n collisionPadding={8}\n >\n <Popover.Popup\n className={cn('header__popup', isMobile && 'header__popup--wide')}\n onClick={() => setIsOpen(false)}\n >\n {children}\n </Popover.Popup>\n </Popover.Positioner>\n </Popover.Portal>\n </Popover.Root>\n </div>\n );\n};\n\n/** The pad of a dropdown. Its `id` is where products hang their overrides. */\nconst HeaderDropdown = ({id, className, children}: HeaderDropdownProps) => (\n <div id={id} className={cn('header__dropdown', className)}>\n {children}\n </div>\n);\n\n/** Rows of a menu: what is in a row fills it, so the whole row is the hit area. */\nconst HeaderDropdownList = ({items = []}: HeaderDropdownListProps) => (\n <div className=\"header__menu\">\n {items.map((item, index) => (\n // The rows are whatever the product passed and carry no identity of their own.\n <div key={index} className=\"header__menu-item\">\n {item}\n </div>\n ))}\n </div>\n);\n\nexport {HeaderDropdown, HeaderDropdownList, HeaderItem};\n","import {Position, Tooltip, TooltipContent, TooltipTrigger} from '@propellerads/smart-tooltip';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport {useEffect, useState} from 'react';\nimport type {HeaderTimeProps} from './types';\n\ndayjs.extend(utc);\n\n/* v7's arithmetic, kept as is: UTC−5 all year, with no daylight saving. */\nconst now = () => dayjs.utc().subtract(5, 'hour');\n\nconst defaultContent: NonNullable<HeaderTimeProps['tooltipContent']> = (date) =>\n `System time: ${date.format('HH:mm DD.MM')} (EST)`;\n\n/** The system time, in EST, with the date in a tooltip. */\nconst HeaderTime = ({tooltipContent = defaultContent}: HeaderTimeProps) => {\n const [time, setTime] = useState(now);\n\n useEffect(() => {\n const timer = setInterval(() => setTime(now()), 1000);\n\n return () => clearInterval(timer);\n }, []);\n\n return (\n <Tooltip>\n <TooltipTrigger render={<span />} className=\"header__time\">\n {`${time.format('HH:mm')} EST`}\n </TooltipTrigger>\n <TooltipContent side={Position.Bottom}>{tooltipContent(time)}</TooltipContent>\n </Tooltip>\n );\n};\n\nexport {HeaderTime};\n","import type {Dayjs} from 'dayjs';\nimport type {CSSProperties, ReactNode} from 'react';\n\n/**\n * What the bar is worn in.\n *\n * `light` is the page itself: the tokens' surface and text, so it turns over\n * with the theme the product writes on <html>. `dark` stays dark on a light\n * page as well — the dark theme's greys, scoped to the bar and its dropdowns.\n * `transparent` is `light` with the surface and the shadow taken away, for a\n * bar laid over a page that draws its own background.\n */\nexport const ThemeName = {\n Dark: 'dark',\n Light: 'light',\n Transparent: 'transparent',\n} as const;\nexport type ThemeName = (typeof ThemeName)[keyof typeof ThemeName];\n\nexport type HeaderProps = {\n /** The brand: a logo, a link home. */\n logo: ReactNode;\n /** Stands before the logo, usually an `Header.Item` that opens the sidebar. */\n sidebarButton?: ReactNode;\n /** The right-hand side: items, dividers, the balance, the time. */\n children: ReactNode;\n /** @default 'light' */\n theme?: ThemeName;\n /** @default 'header-container' — products find the bar by it. */\n id?: string;\n className?: string;\n style?: CSSProperties;\n /** @deprecated Use `style`. Kept for the products that still pass it. */\n customHeaderStyle?: CSSProperties;\n};\n\nexport type HeaderItemProps = {\n /** Lands on the item's wrapper. */\n id?: string;\n className?: string;\n /**\n * The dropdown, usually a `Header.Dropdown`. Clicking the item opens it,\n * clicking anything inside it closes it. Ignored when `onClick` is given.\n */\n children?: ReactNode;\n /** Makes the item a plain button: no dropdown opens. */\n onClick?: () => void;\n /** Free content of the button, after the icon and the title. */\n component?: ReactNode;\n icon?: ReactNode;\n title?: string;\n /** Aligns the dropdown to the item's right edge instead of its left. */\n isRightDropdown?: boolean;\n /** The button's accessible name, for an item that is only an icon. */\n 'aria-label'?: string;\n};\n\nexport type HeaderDropdownProps = {\n id?: string;\n className?: string;\n children: ReactNode;\n};\n\nexport type HeaderDropdownListProps = {\n /** One row each. A link or a button in a row fills the whole row. */\n items?: ReactNode[];\n};\n\nexport type DayEarned = {\n date: string;\n value: number;\n /** The bar's height, 0–100. Below 1 the bar is a hairline. */\n percentage: number;\n};\n\nexport type HeaderBalanceProps = {\n balance: number;\n /** A bar per day beside the balance, hidden below the tablet breakpoint. */\n dailyEarned?: DayEarned[];\n};\n\nexport type HeaderTimeProps = {\n /** What the tooltip says, given the current time in EST. */\n tooltipContent?: (ESTDate: Dayjs) => ReactNode;\n};\n","import {useMemo, useRef} from 'react';\nimport './header.css';\nimport {HeaderBalance} from './balance';\nimport {cn} from './cn';\nimport {HeaderContext} from './context';\nimport {HeaderDropdown, HeaderDropdownList, HeaderItem} from './item';\nimport {HeaderTime} from './time';\nimport {\n type DayEarned,\n type HeaderBalanceProps,\n type HeaderDropdownListProps,\n type HeaderDropdownProps,\n type HeaderItemProps,\n type HeaderProps,\n type HeaderTimeProps,\n ThemeName,\n} from './types';\n\n/**\n * v7 took a theme object and products wrote `theme={themes.dark}`. The object\n * is a name now, and `themes` maps each name onto itself, so that line keeps\n * working.\n *\n * @deprecated Pass `ThemeName.Dark` or `'dark'`.\n */\nconst themes: Record<ThemeName, ThemeName> = {\n [ThemeName.Dark]: ThemeName.Dark,\n [ThemeName.Light]: ThemeName.Light,\n [ThemeName.Transparent]: ThemeName.Transparent,\n};\n\n/* A product may still hand over a v7 theme object, a copy of one or one of\n its own; it gets the light bar rather than a broken one. */\nconst toThemeName = (theme: unknown): ThemeName =>\n Object.values(ThemeName).includes(theme as ThemeName) ? (theme as ThemeName) : ThemeName.Light;\n\nconst HeaderDivider = () => <span className=\"header__divider\" aria-hidden=\"true\" />;\n\nconst HeaderRoot = ({\n logo,\n sidebarButton,\n children,\n theme,\n id = 'header-container',\n className,\n style,\n customHeaderStyle,\n}: HeaderProps) => {\n const barRef = useRef<HTMLElement | null>(null);\n const themeName = toThemeName(theme);\n const context = useMemo(() => ({barRef, theme: themeName}), [themeName]);\n\n return (\n <HeaderContext.Provider value={context}>\n <header\n ref={barRef}\n id={id}\n className={cn('header', `header-theme--${themeName}`, className)}\n style={{...customHeaderStyle, ...style}}\n >\n <div className=\"header__brand\">\n {sidebarButton}\n {logo}\n </div>\n\n <div className=\"header__options\">{children}</div>\n </header>\n </HeaderContext.Provider>\n );\n};\n\ntype HeaderCompound = typeof HeaderRoot & {\n Item: typeof HeaderItem;\n Balance: typeof HeaderBalance;\n Time: typeof HeaderTime;\n Divider: typeof HeaderDivider;\n Dropdown: typeof HeaderDropdown;\n DropdownList: typeof HeaderDropdownList;\n};\n\nconst Header: HeaderCompound = Object.assign(HeaderRoot, {\n Item: HeaderItem,\n Balance: HeaderBalance,\n Time: HeaderTime,\n Divider: HeaderDivider,\n Dropdown: HeaderDropdown,\n DropdownList: HeaderDropdownList,\n});\n\nexport default Header;\nexport type {\n DayEarned,\n HeaderBalanceProps,\n HeaderDropdownListProps,\n HeaderDropdownProps,\n HeaderItemProps,\n HeaderProps,\n HeaderTimeProps,\n};\nexport {\n Header,\n HeaderBalance,\n HeaderDivider,\n HeaderDropdown,\n HeaderDropdownList,\n HeaderItem,\n HeaderTime,\n ThemeName,\n themes,\n};\n"],"mappings":";;;;;;;;AAKA,IAAM,KAAe,GAAe,IAAW,MAAM,EAAM,QAAQ,EAAS,CAAC,QAAQ,uBAAuB,MAAM,EAE5G,KAAS,EAAC,UAAO,kBACrB,kBAAC,QAAD,EAAA,UAAA,CACE,kBAAC,QAAD;CAAM,WAAU;WAAmB;CAAQ,CAAA,EAC1C,EAAY,GAAO,EAAS,CACxB,EAAA,CAAA,EAGH,KAAO,EAAC,aACZ,kBAAC,GAAD,EAAA,UAAA,CACE,kBAAC,GAAD;CAAgB,QAAQ,kBAAC,QAAD,EAAQ,CAAA;CAAE,WAAU;WAC1C,kBAAC,QAAD;EAAM,WAAU;EAAoB,OAAO,EAAC,QAAQ,EAAI,aAAa,IAAI,GAAG,EAAI,WAAW,KAAK,OAAM;EAAI,CAAA;CAC3F,CAAA,EACjB,kBAAC,GAAD;CAAgB,MAAM,EAAS;WAA/B;EACG,EAAI;EAAK;EAAG,kBAAC,GAAD,EAAO,OAAO,EAAI,OAAS,CAAA;EACzB;GACT,EAAA,CAAA,EAQN,KAAiB,EAAC,YAAS,iBAAc,EAAE,OAC/C,kB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K,OAAO,QAAQ,CAAC;EACV,CAAA,EACjB,kBAAC,GAAD;EAAgB,MAAM,EAAS;YAAS,EAAe,EAAK;EAAkB,CAAA,CACtE,EAAA,CAAA;GClBD,IAAY;CACvB,MAAM;CACN,OAAO;CACP,aAAa;CACd,ECSK,IAAuC;EAC1C,EAAU,OAAO,EAAU;EAC3B,EAAU,QAAQ,EAAU;EAC5B,EAAU,cAAc,EAAU;CACpC,EAIK,KAAe,MACnB,OAAO,OAAO,EAAU,CAAC,SAAS,EAAmB,GAAI,IAAsB,EAAU,OAErF,UAAsB,kBAAC,QAAD;CAAM,WAAU;CAAkB,eAAY;CAAS,CAAA,EA4C7E,IAAyB,OAAO,QA1ClB,EAClB,SACA,kBACA,aACA,UACA,QAAK,oBACL,cACA,UACA,2BACiB;CACjB,IAAM,IAAS,EAA2B,KAAK,EACzC,IAAY,EAAY,EAAM,EAC9B,IAAU,SAAe;EAAC;EAAQ,OAAO;EAAU,GAAG,CAAC,EAAU,CAAC;CAExE,OACE,kBAAC,EAAc,UAAf;EAAwB,OAAO;YAC7B,kBAAC,UAAD;GACE,KAAK;GACD;GACJ,WAAW,EAAG,UAAU,iBAAiB,KAAa,EAAU;GAChE,OAAO;IAAC,GAAG;IAAmB,GAAG;IAAM;aAJzC,CAME,kBAAC,OAAD;IAAK,WAAU;cAAf,CACG,GACA,EACG;OAEN,kBAAC,OAAD;IAAK,WAAU;IAAmB;IAAe,CAAA,CAC1C;;EACc,CAAA;GAa4B;CACvD,MAAM;CACN,SAAS;CACT,MAAM;CACN,SAAS;CACT,UAAU;CACV,cAAc;CACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propellerads/header",
3
- "version": "8.0.0",
3
+ "version": "9.0.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/index.css",
@@ -30,12 +30,12 @@
30
30
  "private": false,
31
31
  "dependencies": {
32
32
  "@base-ui-components/react": "1.0.0-rc.0",
33
- "@propellerads/smart-tooltip": "^8.0.0",
33
+ "@propellerads/smart-tooltip": "^9.0.0",
34
34
  "clsx": "^2.1.1",
35
35
  "dayjs": "^1.11.20"
36
36
  },
37
37
  "peerDependencies": {
38
- "@propellerads/tokens": ">=0.3.0",
38
+ "@propellerads/tokens": ">=0.4.0",
39
39
  "react": "^18.0.0 || ^19.0.0",
40
40
  "react-dom": "^18.0.0 || ^19.0.0"
41
41
  },