@tangible/ui 0.2.1 → 0.2.3

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.
@@ -1,9 +1,19 @@
1
1
  import React from 'react';
2
2
  import type { JSX } from 'react';
3
3
  type RootAs = 'article' | 'section' | 'div';
4
+ /** Surface treatment. */
5
+ export type CardVariant = 'solid' | 'outline' | 'ghost' | 'elevated' | 'seamless';
6
+ /** Content arrangement (a structural mode). (`gallery` — Phase 2.) */
7
+ export type CardMode = 'stacked' | 'inline';
4
8
  type CommonProps = {
5
- inline?: boolean;
9
+ /** Surface treatment. @default 'solid' */
10
+ variant?: CardVariant;
11
+ /** Content arrangement. @default 'stacked' */
12
+ mode?: CardMode;
13
+ /** @deprecated Use `variant="elevated"`. */
6
14
  elevated?: boolean;
15
+ /** @deprecated Use `mode="inline"`. */
16
+ inline?: boolean;
7
17
  interactive?: boolean;
8
18
  disabled?: boolean;
9
19
  className?: string;
@@ -19,11 +29,18 @@ type SlotProps = React.HTMLAttributes<HTMLDivElement> & {
19
29
  className?: string;
20
30
  children?: React.ReactNode;
21
31
  };
32
+ export type CardMediaProps = Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'alt'> & {
33
+ /** Full-bleed media (negative-margin, square outer corners). @default true */
34
+ flush?: boolean;
35
+ /** Alt text — pass `""` for decorative media. */
36
+ alt: string;
37
+ };
22
38
  type CardCompound = {
23
39
  <TAs extends RootAs = 'article'>(props: CardRootProps<TAs> & Omit<React.ComponentPropsWithoutRef<TAs>, keyof CardRootProps>): JSX.Element;
24
40
  Head: React.FC<SlotProps>;
25
41
  Body: React.FC<SlotProps>;
26
42
  Foot: React.FC<SlotProps>;
43
+ Media: React.FC<CardMediaProps>;
27
44
  Link: React.FC<React.AnchorHTMLAttributes<HTMLAnchorElement>>;
28
45
  };
29
46
  export declare const Card: CardCompound;
@@ -3,14 +3,31 @@ import React, { forwardRef, useRef, useEffect, createContext, useContext } from
3
3
  import { cx } from '../../utils/cx.js';
4
4
  import { isDev } from '../../utils/is-dev.js';
5
5
  const CardDisabledContext = createContext(false);
6
- export const Card = forwardRef(function Card({ as = 'article', inline, elevated, interactive, disabled, className, style, onClick, children, ...rest }, ref) {
6
+ export const Card = forwardRef(function Card({ as = 'article', variant, mode, inline, elevated, interactive, disabled, className, style, onClick, children, ...rest }, ref) {
7
7
  const Tag = as;
8
+ // Resolve the new axes, honouring the deprecated `elevated`/`inline` aliases.
9
+ // An explicit new prop always wins over its alias.
10
+ const resolvedVariant = variant ?? (elevated ? 'elevated' : 'solid');
11
+ const resolvedMode = mode ?? (inline ? 'inline' : 'stacked');
8
12
  // Dev warning: suggest Card.Link for interactive cards.
9
13
  // The recursive children walk is gated behind isDev() to avoid
10
14
  // unnecessary work in production on every render.
15
+ const deprecationWarnedRef = useRef(false);
16
+ useEffect(() => {
17
+ if (!isDev() || deprecationWarnedRef.current)
18
+ return;
19
+ if (elevated !== undefined) {
20
+ deprecationWarnedRef.current = true;
21
+ console.warn(`[TUI Card] \`elevated\` is deprecated — use \`variant="elevated"\`.${variant !== undefined ? ' Both were passed; `variant` wins.' : ''}`);
22
+ }
23
+ if (inline !== undefined) {
24
+ deprecationWarnedRef.current = true;
25
+ console.warn(`[TUI Card] \`inline\` is deprecated — use \`mode="inline"\`.${mode !== undefined ? ' Both were passed; `mode` wins.' : ''}`);
26
+ }
27
+ }, [elevated, inline, variant, mode]);
11
28
  const warnedRef = useRef(false);
12
29
  useEffect(() => {
13
- if (!isDev() || warnedRef.current || !(interactive || onClick))
30
+ if (!isDev() || warnedRef.current)
14
31
  return;
15
32
  const hasCardLinkChild = (function checkChildren(nodes) {
16
33
  return React.Children.toArray(nodes).some((child) => {
@@ -25,13 +42,20 @@ export const Card = forwardRef(function Card({ as = 'article', inline, elevated,
25
42
  return false;
26
43
  });
27
44
  })(children);
28
- if (!hasCardLinkChild) {
45
+ // Interactive without an accessible click target.
46
+ if ((interactive || onClick) && !hasCardLinkChild) {
29
47
  warnedRef.current = true;
30
48
  console.warn('[TUI Card] Interactive cards should use <Card.Link> for accessible click targets. ' +
31
49
  '`interactive` and `onClick` provide visual hover styles but no keyboard/screen-reader semantics.');
32
50
  }
51
+ // A click target with no hover/focus affordance — the inverse footgun.
52
+ else if (hasCardLinkChild && !interactive && !onClick) {
53
+ warnedRef.current = true;
54
+ console.warn('[TUI Card] A <Card.Link> card has no hover/focus affordance — add `interactive` ' +
55
+ 'so mouse users get feedback (keyboard focus already shows the stretched-link ring).');
56
+ }
33
57
  });
34
- const classes = cx('tui-card', inline && 'is-layout-inline', elevated && 'is-style-elevated', interactive && 'has-interaction', className);
58
+ const classes = cx('tui-card', `is-style-${resolvedVariant}`, resolvedMode !== 'stacked' && `is-layout-${resolvedMode}`, interactive && 'has-interaction', className);
35
59
  return (_jsx(Tag, { ref: ref, className: classes, style: style, "aria-disabled": disabled || undefined, onClick: disabled ? undefined : onClick, ...rest, children: _jsx(CardDisabledContext.Provider, { value: !!disabled, children: _jsx("div", { className: "tui-card__inner", children: children }) }) }));
36
60
  });
37
61
  function CardHead({ className, children, ...rest }) {
@@ -51,7 +75,20 @@ function CardLink({ className, children, rel, target, href, ...rest }) {
51
75
  return (_jsx("a", { className: cx('tui-stretched-link', className), rel: target === '_blank' ? ['noopener', 'noreferrer', rel].filter(Boolean).join(' ') : rel, target: isDisabled ? undefined : target, href: isDisabled ? undefined : href, role: isDisabled ? 'link' : undefined, "aria-disabled": isDisabled || undefined, tabIndex: isDisabled ? -1 : undefined, ...rest, children: children }));
52
76
  }
53
77
  CardLink.displayName = 'Card.Link';
78
+ // Ergonomic wrapper over the existing `tui-card__media` / `is-flush` CSS (which
79
+ // handles full-bleed top/bottom in stacked and side object-fit:cover in inline).
80
+ // img-based for now; video/picture keep the className escape hatch.
81
+ function CardMedia({ className, flush = true, alt, ...rest }) {
82
+ // `alt` is required in TS, but props often arrive from PHP/YAML config (Fields/
83
+ // Object) outside the type check — warn in dev if it's missing entirely.
84
+ if (isDev() && alt === undefined) {
85
+ console.warn('[TUI Card] <Card.Media> is missing `alt` — pass a description, or "" for decorative media.');
86
+ }
87
+ return _jsx("img", { className: cx('tui-card__media', flush && 'is-flush', className), alt: alt, ...rest });
88
+ }
89
+ CardMedia.displayName = 'Card.Media';
54
90
  Card.Head = CardHead;
55
91
  Card.Body = CardBody;
56
92
  Card.Foot = CardFoot;
93
+ Card.Media = CardMedia;
57
94
  Card.Link = CardLink;
@@ -1,2 +1,2 @@
1
1
  export { Card } from './Card';
2
- export type { CardRootProps } from './Card';
2
+ export type { CardRootProps, CardVariant, CardMode, CardMediaProps } from './Card';
@@ -44,7 +44,7 @@ export { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from './Tool
44
44
  export type { AccordionProps, AccordionSingleProps, AccordionMultipleProps, AccordionItemProps, AccordionTriggerProps, AccordionPanelProps, } from './Accordion';
45
45
  export type { AvatarProps, AvatarGroupProps, AvatarSize, AvatarShape, IndicatorPosition, } from './Avatar';
46
46
  export type { ButtonProps } from './Button';
47
- export type { CardRootProps } from './Card';
47
+ export type { CardRootProps, CardVariant, CardMode, CardMediaProps } from './Card';
48
48
  export type { CheckboxProps } from './Checkbox';
49
49
  export type { ChipProps } from './Chip';
50
50
  export type { ChipGroupProps, ChipGroupSingleProps, ChipGroupMultipleProps } from './ChipGroup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",