@pixerate/editor-react 0.170.0 → 0.171.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.
@@ -0,0 +1,51 @@
1
+ // src/stickers/StickerLibraryPicker.tsx
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { StickerBrowser } from "@pixerate/editor/stickers";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ var StickerLibraryPicker = ({ provider, selected = [], onPick, label = "Stickers", footer, className }) => {
6
+ const browser = useMemo(() => new StickerBrowser(() => provider), [provider]);
7
+ const [, setTick] = useState(0);
8
+ useEffect(() => {
9
+ const off = browser.subscribe(() => setTick((n) => n + 1));
10
+ void browser.refresh();
11
+ return off;
12
+ }, [browser]);
13
+ const s = browser.state;
14
+ return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-1 ${className ?? ""}`, "data-testid": "sticker-picker", children: [
15
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
16
+ /* @__PURE__ */ jsx("input", { type: "search", "aria-label": `Search ${label.toLowerCase()}`, placeholder: `Search ${s.provider}`, value: s.query, onChange: (e) => void browser.setQuery(e.target.value), className: "min-w-0 flex-1 rounded bg-slate-800 px-1 py-0.5" }),
17
+ s.categories.length > 1 && /* @__PURE__ */ jsxs("select", { "aria-label": "Sticker category", value: s.category, onChange: (e) => void browser.setCategory(e.target.value), className: "rounded bg-slate-800 px-1 py-0.5", children: [
18
+ /* @__PURE__ */ jsx("option", { value: "", children: "All" }),
19
+ s.categories.map((c) => /* @__PURE__ */ jsx("option", { value: c.id, children: c.name }, c.id))
20
+ ] })
21
+ ] }),
22
+ /* @__PURE__ */ jsx("div", { className: "flex max-h-32 flex-wrap gap-1 overflow-y-auto", role: "group", "aria-label": label, children: s.items.map((it) => {
23
+ const on = selected.includes(it.ref);
24
+ return /* @__PURE__ */ jsxs(
25
+ "button",
26
+ {
27
+ type: "button",
28
+ "aria-pressed": on,
29
+ title: `${it.name} (${it.ref}) \xB7 ${it.licence.name}${it.licence.attribution ? ` \xB7 ${it.licence.attribution}` : ""}`,
30
+ className: `flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300"}`,
31
+ onClick: () => onPick(it),
32
+ children: [
33
+ it.thumbnail && /* @__PURE__ */ jsx("img", { src: it.thumbnail, alt: "", className: "h-4 w-4" }),
34
+ it.name
35
+ ]
36
+ },
37
+ it.ref
38
+ );
39
+ }) }),
40
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-[10px] text-slate-500", children: [
41
+ /* @__PURE__ */ jsx("span", { children: s.loading ? "Loading\u2026" : `${s.items.length} of ${s.total}` }),
42
+ s.hasMore && /* @__PURE__ */ jsx("button", { type: "button", className: "text-indigo-300", onClick: () => void browser.more(), children: "More" })
43
+ ] }),
44
+ s.error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-[11px] text-rose-400", children: s.error }),
45
+ footer
46
+ ] });
47
+ };
48
+
49
+ export {
50
+ StickerLibraryPicker
51
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import type { PaintEditorController } from '@pixerate/editor/paint-editor';
3
3
  export interface StickerPickerProps {
4
4
  controller: PaintEditorController;
5
5
  /** Refs shown as chosen. */
@@ -10,8 +10,8 @@ export interface StickerPickerProps {
10
10
  label?: string;
11
11
  }
12
12
  /**
13
- * Stickers from the paint editor's sticker library (`controller.stickersProvider`), searchable,
14
- * by category and a page at a time; clicking one calls `onPick` with its ref. Chosen stickers
15
- * whose art failed to load say why.
13
+ * Stickers from the paint editor's sticker library (`controller.stickersProvider`, followed when
14
+ * it changes), through `StickerLibraryPicker`; clicking one calls `onPick` with its ref. Chosen
15
+ * stickers whose art failed to load say why.
16
16
  */
17
17
  export declare const StickerPicker: React.FC<StickerPickerProps>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import type { PaintEditorController } from '@pixerate/editor/paint-editor';
3
3
  export interface StickerPickerProps {
4
4
  controller: PaintEditorController;
5
5
  /** Refs shown as chosen. */
@@ -10,8 +10,8 @@ export interface StickerPickerProps {
10
10
  label?: string;
11
11
  }
12
12
  /**
13
- * Stickers from the paint editor's sticker library (`controller.stickersProvider`), searchable,
14
- * by category and a page at a time; clicking one calls `onPick` with its ref. Chosen stickers
15
- * whose art failed to load say why.
13
+ * Stickers from the paint editor's sticker library (`controller.stickersProvider`, followed when
14
+ * it changes), through `StickerLibraryPicker`; clicking one calls `onPick` with its ref. Chosen
15
+ * stickers whose art failed to load say why.
16
16
  */
17
17
  export declare const StickerPicker: React.FC<StickerPickerProps>;