{
  "name": "solid-example-text-color",
  "title": "solid-example-text-color",
  "type": "registry:block",
  "description": "Change text and background color.",
  "registryDependencies": [
    "https://unpkg.com/prosekit-registry/dist/r/solid-sample-sample-doc-text-color.json",
    "https://unpkg.com/prosekit-registry/dist/r/solid-ui-button.json"
  ],
  "dependencies": [
    "prosekit@^0.23.2"
  ],
  "files": [
    {
      "path": "registry/src/solid/examples/text-color/editor.tsx",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/editor.tsx",
      "content": "import 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport { createEditor, type NodeJSON } from 'prosekit/core'\nimport { ProseKit } from 'prosekit/solid'\nimport type { JSX } from 'solid-js'\n\nimport { sampleContent } from '../../sample/sample-doc-text-color.ts'\n\nimport { defineExtension } from './extension.ts'\nimport InlineMenu from './inline-menu.tsx'\n\ninterface EditorProps {\n  initialContent?: NodeJSON\n}\n\nexport default function Editor(props: EditorProps): JSX.Element {\n  const defaultContent = props.initialContent ?? sampleContent\n  const extension = defineExtension()\n  const editor = createEditor({ extension, defaultContent })\n\n  return (\n    <ProseKit editor={editor}>\n      <div class=\"box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-[canvas] text-black dark:text-white\">\n        <div class=\"relative w-full flex-1 box-border overflow-y-auto\">\n          <div ref={editor.mount} class=\"ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500\"></div>\n          <InlineMenu />\n        </div>\n      </div>\n    </ProseKit>\n  )\n}\n"
    },
    {
      "path": "registry/src/solid/examples/text-color/extension.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/extension.ts",
      "content": "import { defineBasicExtension } from 'prosekit/basic'\nimport { union } from 'prosekit/core'\nimport { defineBackgroundColor } from 'prosekit/extensions/background-color'\nimport { defineTextColor } from 'prosekit/extensions/text-color'\n\nexport function defineExtension() {\n  return union(defineBasicExtension(), defineTextColor(), defineBackgroundColor())\n}\n\nexport type EditorExtension = ReturnType<typeof defineExtension>\n"
    },
    {
      "path": "registry/src/solid/examples/text-color/index.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/index.ts",
      "content": "export { default as ExampleEditor } from './editor.tsx'\n"
    },
    {
      "path": "registry/src/solid/examples/text-color/inline-menu.tsx",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/inline-menu.tsx",
      "content": "import type { Editor, Keymap } from 'prosekit/core'\nimport { useEditorDerivedValue, useKeymap } from 'prosekit/solid'\nimport { InlinePopoverPopup, InlinePopoverPositioner, InlinePopoverRoot } from 'prosekit/solid/inline-popover'\nimport { createSignal, For, type JSX } from 'solid-js'\n\nimport { Button } from '../../ui/button/index.ts'\n\nimport type { EditorExtension } from './extension.ts'\n\nconst textColors = [\n  { label: 'Gray', value: '#9ca3af' },\n  { label: 'Brown', value: '#92400e' },\n  { label: 'Orange', value: '#ea580c' },\n  { label: 'Yellow', value: '#ca8a04' },\n  { label: 'Green', value: '#16a34a' },\n  { label: 'Blue', value: '#2563eb' },\n  { label: 'Purple', value: '#9333ea' },\n  { label: 'Magenta', value: '#c026d3' },\n  { label: 'Red', value: '#dc2626' },\n]\n\nconst backgroundColors = [\n  { label: 'Gray', value: '#f3f4f6' },\n  { label: 'Brown', value: '#fef3c7' },\n  { label: 'Orange', value: '#ffedd5' },\n  { label: 'Yellow', value: '#fef9c3' },\n  { label: 'Green', value: '#d1fae5' },\n  { label: 'Blue', value: '#dbeafe' },\n  { label: 'Purple', value: '#e9d5ff' },\n  { label: 'Pink', value: '#fce7f3' },\n  { label: 'Red', value: '#fecaca' },\n]\n\nfunction getTextColorState(editor: Editor<EditorExtension>) {\n  return [\n    {\n      label: 'Default',\n      value: 'currentColor',\n      isActive: !editor.marks.textColor.isActive(),\n      onClick: () => editor.commands.removeTextColor(),\n    },\n  ].concat(\n    textColors.map((color) => ({\n      label: color.label,\n      value: color.value,\n      isActive: editor.marks.textColor.isActive({ color: color.value }),\n      onClick: () => editor.commands.addTextColor({ color: color.value }),\n    })),\n  )\n}\n\nfunction getBackgroundColorState(editor: Editor<EditorExtension>) {\n  return [\n    {\n      label: 'Default',\n      value: 'canvas',\n      isActive: !editor.marks.backgroundColor.isActive(),\n      onClick: () => editor.commands.removeBackgroundColor(),\n    },\n  ].concat(\n    backgroundColors.map((color) => ({\n      label: color.label,\n      value: color.value,\n      isActive: editor.marks.backgroundColor.isActive({ color: color.value }),\n      onClick: () => editor.commands.addBackgroundColor({ color: color.value }),\n    })),\n  )\n}\n\nexport default function InlineMenu(): JSX.Element {\n  const textColorState = useEditorDerivedValue(getTextColorState)\n  const backgroundColorState = useEditorDerivedValue(getBackgroundColorState)\n  const [open, setOpen] = createSignal(false)\n\n  const keymap: () => Keymap = () => ({\n    Escape: () => {\n      if (open()) {\n        setOpen(false)\n        return true\n      }\n      return false\n    },\n  })\n\n  useKeymap(keymap)\n\n  return (\n    <InlinePopoverRoot\n      open={open()}\n      onOpenChange={(event) => setOpen(event.detail)}\n    >\n      <InlinePopoverPositioner class=\"block overflow-visible w-min h-min z-50 ease-out transition-transform duration-100 motion-reduce:transition-none\">\n        <InlinePopoverPopup class=\"box-border origin-(--transform-origin) transition-[opacity,scale] transition-discrete motion-reduce:transition-none data-[state=closed]:duration-150 data-[state=closed]:opacity-0 starting:opacity-0 data-[state=closed]:scale-95 starting:scale-95 duration-40 border border-gray-200 dark:border-gray-800 shadow-lg bg-[canvas] relative flex min-w-32 space-x-1 overflow-auto whitespace-nowrap rounded-lg p-1\">\n          <div class=\"flex flex-col gap-4 p-4 w-60\">\n            <div class=\"flex flex-col gap-2\">\n              <div class=\"text-sm\">Text color</div>\n              <div class=\"grid grid-cols-5 gap-1\">\n                <For each={textColorState()}>\n                  {(color) => (\n                    <Button\n                      pressed={color.isActive}\n                      tooltip={`Text: ${color.label}`}\n                      onClick={color.onClick}\n                    >\n                      <span\n                        class=\"text-base font-medium\"\n                        style={{ color: color.value }}\n                      >\n                        A\n                      </span>\n                    </Button>\n                  )}\n                </For>\n              </div>\n            </div>\n            <div class=\"flex flex-col gap-2\">\n              <div class=\"text-sm\">Background color</div>\n              <div class=\"grid grid-cols-5 gap-1\">\n                <For each={backgroundColorState()}>\n                  {(color) => (\n                    <Button\n                      pressed={color.isActive}\n                      tooltip={`Background: ${color.label}`}\n                      onClick={color.onClick}\n                    >\n                      <div\n                        class=\"w-6 h-6 rounded border border-gray-200 dark:border-gray-700\"\n                        style={{ 'background-color': color.value }}\n                      />\n                    </Button>\n                  )}\n                </For>\n              </div>\n            </div>\n          </div>\n        </InlinePopoverPopup>\n      </InlinePopoverPositioner>\n    </InlinePopoverRoot>\n  )\n}\n"
    }
  ],
  "meta": {
    "hasIcons": false,
    "hidden": false,
    "story": "text-color",
    "framework": "solid",
    "accumulatedFiles": [
      "registry/src/solid/examples/text-color/editor.tsx",
      "registry/src/solid/examples/text-color/extension.ts",
      "registry/src/solid/examples/text-color/index.ts",
      "registry/src/solid/examples/text-color/inline-menu.tsx",
      "registry/src/solid/sample/sample-doc-text-color.ts",
      "registry/src/solid/ui/button/button.tsx",
      "registry/src/solid/ui/button/index.ts"
    ],
    "internalDependencies": [
      "solid-sample-sample-doc-text-color",
      "solid-ui-button"
    ]
  },
  "$schema": "https://ui.shadcn.com/schema/registry-item.json"
}
