@alulore/kumiko 0.15.0 → 0.15.1

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.
@@ -45,6 +45,14 @@ export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
45
45
  over?: boolean;
46
46
  /** A well with a solid fill, for use as a drop target on a busy background. */
47
47
  solid?: boolean;
48
+ /**
49
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
50
+ * `onClick`) is pressable and a plain `div` is not. `true` makes a plain card react too, for a card that something
51
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
52
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
53
+ * props is ignored.
54
+ */
55
+ pressable?: boolean;
48
56
  /** The lamp at the start of a banner. */
49
57
  lamp?: React.ReactNode;
50
58
  /** The actions at the end of a banner. */
@@ -54,9 +62,16 @@ export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
54
62
  };
55
63
  /** An empty data attribute when on, and none when off. */
56
64
  export declare function flag(on: boolean | undefined): string | undefined;
65
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
66
+ export declare function isPressable(pressable: boolean | undefined, natural: boolean, off: {
67
+ disabled: boolean;
68
+ readOnly: boolean;
69
+ }): boolean;
70
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
71
+ export declare function withoutPressable(props: object): Record<string, unknown>;
57
72
  /**
58
73
  * A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
59
74
  * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
60
75
  * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
61
76
  */
62
- export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
77
+ export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, pressable, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
package/dist/card/card.js CHANGED
@@ -12,6 +12,14 @@ export function lookAttributes(looks) {
12
12
  export function flag(on) {
13
13
  return on ? "" : undefined;
14
14
  }
15
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
16
+ export function isPressable(pressable, natural, off) {
17
+ return !off.disabled && !off.readOnly && (pressable ?? natural);
18
+ }
19
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
20
+ export function withoutPressable(props) {
21
+ return Object.fromEntries(Object.entries(props).filter(([name]) => name !== "data-pressable"));
22
+ }
15
23
  /** A banner's row: the lamp, the body and the actions. */
16
24
  function banner(lamp, children, actions) {
17
25
  return (_jsxs(_Fragment, { children: [lamp ? _jsx("div", { "data-slot": "card-lamp", children: lamp }) : null, _jsx("div", { "data-slot": "card-body", children: children }), actions ? _jsx("div", { "data-slot": "card-actions", children: actions }) : null] }));
@@ -21,7 +29,7 @@ function banner(lamp, children, actions) {
21
29
  * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
22
30
  * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
23
31
  */
24
- export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
32
+ export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, pressable, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
25
33
  const asButton = !readOnly && (variant === "add" || (variant === "interactive" && onClick !== undefined));
26
34
  const common = {
27
35
  "data-slot": "card",
@@ -31,8 +39,7 @@ export function Card({ variant = "surface", surface, hover, press, addLook, disa
31
39
  "data-over": flag(over),
32
40
  "data-solid": flag(solid),
33
41
  "data-readonly": flag(readOnly),
34
- "data-disabled": flag(disabled),
35
- "data-pressable": flag(asButton && !disabled)
42
+ "data-disabled": flag(disabled)
36
43
  };
37
44
  const kind = asButton
38
45
  ? { type: "button", disabled, onClick }
@@ -41,7 +48,8 @@ export function Card({ variant = "surface", surface, hover, press, addLook, disa
41
48
  return renderElement(asButton ? "button" : "div", {
42
49
  ...common,
43
50
  ...kind,
44
- ...props,
51
+ ...withoutPressable(props),
52
+ "data-pressable": flag(isPressable(pressable, asButton, { disabled, readOnly })),
45
53
  ref,
46
54
  children: body
47
55
  });
@@ -19,6 +19,14 @@ export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
19
19
  disabled?: boolean;
20
20
  /** Shown as it is, with no hover, press or pointer cursor, and not dimmed. */
21
21
  readOnly?: boolean;
22
+ /**
23
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
24
+ * `onClick`) is pressable and a plain box is not. `true` makes a plain card react too, for a card that something
25
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
26
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
27
+ * props is ignored.
28
+ */
29
+ pressable?: boolean;
22
30
  /** Draws the card on its only child, which receives the props. */
23
31
  asChild?: boolean;
24
32
  /** The card's element. With `asChild` it goes to the child. */
@@ -49,7 +57,7 @@ export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
49
57
  * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
50
58
  * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
51
59
  */
52
- export declare function ItemCard({ asChild, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
60
+ export declare function ItemCard({ asChild, pressable: pressableProp, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
53
61
  export type ItemCardEyebrowProps = React.ComponentPropsWithoutRef<"span"> & {
54
62
  /** The colour of the small diamond, any CSS colour. */
55
63
  dot?: string;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { mergeProps, renderElement } from "@ui-sdk/react/primitive";
3
3
  import { Children, isValidElement } from "react";
4
4
  import { Badge } from "../badge/badge";
5
- import { flag, lookAttributes } from "./card";
5
+ import { flag, isPressable, lookAttributes, withoutPressable } from "./card";
6
6
  /** Splits the props into the data attributes that carry the state and looks, and the rest for the element. */
7
7
  function splitProps(props) {
8
8
  const { tone, selected, done, dragging, disabled, readOnly, ...more } = props;
@@ -22,17 +22,23 @@ function splitProps(props) {
22
22
  "aria-disabled": disabled ? true : undefined,
23
23
  ...lookAttributes({ surface, hover, press })
24
24
  };
25
- return { state, dom, disabled: disabled === true, readOnly: readOnly === true };
25
+ return {
26
+ state,
27
+ dom: withoutPressable(dom),
28
+ disabled: disabled === true,
29
+ readOnly: readOnly === true
30
+ };
26
31
  }
27
32
  /**
28
33
  * A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
29
34
  * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
30
35
  * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
31
36
  */
32
- export function ItemCard({ asChild = false, onClick, children, ref, ...props }) {
37
+ export function ItemCard({ asChild = false, pressable: pressableProp, onClick, children, ref, ...props }) {
33
38
  const { state, dom, disabled, readOnly } = splitProps(props);
34
39
  const clickable = onClick !== undefined && !readOnly;
35
- const pressable = { ...state, "data-pressable": flag(clickable && !disabled) };
40
+ const on = isPressable(pressableProp, clickable, { disabled, readOnly });
41
+ const pressable = { ...state, "data-pressable": flag(on) };
36
42
  if (asChild && isValidElement(children)) {
37
43
  const own = { onClick: clickable && !disabled ? onClick : undefined, ref };
38
44
  return renderElement("div", mergeProps(dom, own, pressable), children);
@@ -48,7 +48,8 @@ function syncRoving(list, stop) {
48
48
  return;
49
49
  }
50
50
  const kept = stop && rows.includes(stop) ? stop : null;
51
- const start = kept ?? rows.find((row) => Object.hasOwn(row.dataset, "current")) ?? rows[0];
51
+ const marked = (name) => rows.find((row) => Object.hasOwn(row.dataset, name));
52
+ const start = kept ?? marked("current") ?? marked("selected") ?? rows[0];
52
53
  for (const row of rows) {
53
54
  row.dataset.roving = "";
54
55
  row.tabIndex = row === start ? 0 : -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alulore/kumiko",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Polished, cozy React components with gentle motion, built on ui-sdk. Every look and behaviour can be switched with props and CSS tokens.",
5
5
  "license": "MIT",
6
6
  "repository": {