{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"html-css-button-set-with-primary-secondary-outline-ghost-icon-loading-and-destructive-styles","type":"registry:component","title":"HTML CSS Button Set with Primary, Secondary, Outline, Ghost, Icon, Loading and Destructive Styles","description":"Free HTML CSS button set: primary, secondary, outline, ghost, destructive, icon and loading buttons in three sizes, with hover, press, focus and disabled states.","dependencies":[],"files":[{"path":"components/we-inc/html-css-button-set-with-primary-secondary-outline-ghost-icon-loading-and-destructive-styles.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\n\n// One shared base, then one string per variant and per size.\n// The same strings work as plain HTML on a button element.\nconst base =\n  \"relative inline-flex select-none items-center justify-center gap-2 whitespace-nowrap rounded-lg font-semibold tracking-[-0.01em] \" +\n  \"transition-[background-color,border-color,color,box-shadow,transform] duration-150 ease-out active:translate-y-px active:scale-[0.98] \" +\n  \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-white \" +\n  \"disabled:pointer-events-none disabled:opacity-45 aria-busy:cursor-progress motion-reduce:transition-none motion-reduce:active:translate-y-0 motion-reduce:active:scale-100\";\n\nconst variants = {\n  primary:\n    \"bg-blue-600 text-white shadow-[0_1px_0_0_rgba(255,255,255,0.22)_inset,0_1px_2px_rgba(15,23,42,0.25)] hover:bg-blue-700 active:bg-blue-800 focus-visible:ring-blue-600\",\n  secondary:\n    \"bg-slate-100 text-slate-900 hover:bg-slate-200 active:bg-slate-300 focus-visible:ring-slate-500\",\n  outline:\n    \"border border-slate-300 bg-white text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 hover:bg-slate-50 active:bg-slate-100 focus-visible:ring-slate-500\",\n  ghost:\n    \"text-slate-700 hover:bg-slate-100 hover:text-slate-900 active:bg-slate-200 focus-visible:ring-slate-500\",\n  destructive:\n    \"bg-red-600 text-white shadow-[0_1px_0_0_rgba(255,255,255,0.2)_inset,0_1px_2px_rgba(127,29,29,0.3)] hover:bg-red-700 active:bg-red-800 focus-visible:ring-red-600\",\n  dark:\n    \"bg-slate-900 text-white hover:bg-slate-800 active:bg-black focus-visible:ring-slate-900\",\n} as const;\n\nconst sizes = {\n  sm: \"min-h-[36px] px-3 text-[13px]\",\n  md: \"min-h-[42px] px-4 text-sm\",\n  lg: \"min-h-[50px] px-6 text-base\",\n  icon: \"h-[42px] w-[42px] p-0 [&_svg]:h-[18px] [&_svg]:w-[18px]\",\n} as const;\n\ntype Variant = keyof typeof variants;\ntype Size = keyof typeof sizes;\nconst btn = (variant: Variant = \"primary\", size: Size = \"md\") => `${base} ${variants[variant]} ${sizes[size]}`;\n\nconst icon = \"h-4 w-4 shrink-0\";\nconst Plus = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\" className={icon}><path d=\"M10 4.5v11M4.5 10h11\" /></svg>\n);\nconst Arrow = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className={`${icon} transition-transform duration-150 group-hover:translate-x-0.5 motion-reduce:transition-none`}><path d=\"M4 10h11M11 5.5 15.5 10 11 14.5\" /></svg>\n);\nconst Download = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className={icon}><path d=\"M10 3.5v9M6 8.5l4 4 4-4M4 16h12\" /></svg>\n);\nconst Trash = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className={icon}><path d=\"M4 6h12M8 6V4.5h4V6M6 6l.7 9.5h6.6L14 6\" /></svg>\n);\nconst Pencil = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className={icon}><path d=\"M12.5 4.5l3 3L7 16H4v-3l8.5-8.5Z\" /></svg>\n);\nconst Dots = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"currentColor\" aria-hidden=\"true\" className={icon}><circle cx=\"4.5\" cy=\"10\" r=\"1.5\" /><circle cx=\"10\" cy=\"10\" r=\"1.5\" /><circle cx=\"15.5\" cy=\"10\" r=\"1.5\" /></svg>\n);\nconst Spinner = () => (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\" className={`${icon} animate-spin motion-reduce:animate-none`}>\n    <circle cx=\"10\" cy=\"10\" r=\"7\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"2.2\" />\n    <path d=\"M17 10a7 7 0 0 0-7-7\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" />\n  </svg>\n);\n\n// Frozen copies of each interaction state, so the page shows them without a mouse.\nconst forced: { variant: Variant; label: string; note: string; cls: string }[] = [\n  { variant: \"primary\", label: \"Publish\", note: \"Rest\", cls: \"\" },\n  { variant: \"primary\", label: \"Publish\", note: \"Hover\", cls: \"!bg-blue-700\" },\n  { variant: \"primary\", label: \"Publish\", note: \"Pressed\", cls: \"!bg-blue-800 translate-y-px scale-[0.98]\" },\n  { variant: \"primary\", label: \"Publish\", note: \"Keyboard focus\", cls: \"ring-2 ring-blue-600 ring-offset-2\" },\n  { variant: \"ghost\", label: \"Archive\", note: \"Ghost hover\", cls: \"!bg-slate-100 !text-slate-900\" },\n];\n\nfunction Row({ label, children }: { label: string; children: ReactNode }) {\n  return (\n    <div className=\"grid gap-3 border-t border-slate-200 py-5 first:border-t-0 sm:grid-cols-[156px_1fr] sm:items-center sm:gap-6\">\n      <p className=\"text-xs font-medium uppercase tracking-[0.08em] text-slate-600\">{label}</p>\n      <div className=\"flex flex-wrap items-center gap-3\">{children}</div>\n    </div>\n  );\n}\n\n// A real loading button: click it and it holds a busy state, then confirms.\nfunction SaveButton() {\n  const [state, setState] = useState<\"idle\" | \"loading\" | \"done\">(\"idle\");\n  const timer = useRef<number>();\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n  const run = () => {\n    if (state !== \"idle\") return;\n    setState(\"loading\");\n    timer.current = window.setTimeout(() => {\n      setState(\"done\");\n      timer.current = window.setTimeout(() => setState(\"idle\"), 1600);\n    }, 1800);\n  };\n  return (\n    <button type=\"button\" onClick={run} aria-busy={state === \"loading\"} className={`${btn(\"primary\")} min-w-[148px]`}>\n      {state === \"loading\" ? <Spinner /> : null}\n      <span>{state === \"loading\" ? \"Saving\" : state === \"done\" ? \"Saved\" : \"Save changes\"}</span>\n      <span className=\"sr-only\" aria-live=\"polite\">{state === \"done\" ? \"Changes saved\" : \"\"}</span>\n    </button>\n  );\n}\n\nexport default function HtmlCssButtonSet() {\n  return (\n    <div className=\"min-h-[640px] bg-slate-50 px-4 py-10 sm:px-10 sm:py-14\" style={{ fontFamily: '\"Inter Tight\", Inter, ui-sans-serif, system-ui, sans-serif' }}>\n      <div className=\"mx-auto max-w-[52rem] rounded-2xl border border-slate-200 bg-white px-5 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.04),0_8px_24px_-12px_rgba(15,23,42,0.12)] sm:px-8\">\n        <Row label=\"Variants\">\n          <button type=\"button\" className={btn(\"primary\")}>Primary</button>\n          <button type=\"button\" className={btn(\"secondary\")}>Secondary</button>\n          <button type=\"button\" className={btn(\"outline\")}>Outline</button>\n          <button type=\"button\" className={btn(\"ghost\")}>Ghost</button>\n          <button type=\"button\" className={btn(\"destructive\")}>Delete</button>\n        </Row>\n        <Row label=\"Sizes\">\n          <button type=\"button\" className={btn(\"dark\", \"sm\")}>Small</button>\n          <button type=\"button\" className={btn(\"dark\", \"md\")}>Medium</button>\n          <button type=\"button\" className={btn(\"dark\", \"lg\")}>Large</button>\n        </Row>\n        <Row label=\"With icons\">\n          <button type=\"button\" className={btn(\"primary\")}><Plus />New project</button>\n          <button type=\"button\" className={`group ${btn(\"outline\")}`}>Continue<Arrow /></button>\n          <button type=\"button\" className={btn(\"secondary\")}><Download />Export</button>\n          <span className=\"flex items-center gap-1.5\">\n            <button type=\"button\" aria-label=\"Edit\" className={btn(\"outline\", \"icon\")}><Pencil /></button>\n            <button type=\"button\" aria-label=\"More actions\" className={btn(\"ghost\", \"icon\")}><Dots /></button>\n            <button type=\"button\" aria-label=\"Delete file\" className={btn(\"destructive\", \"icon\")}><Trash /></button>\n          </span>\n        </Row>\n        <Row label=\"Hover, press, focus\">\n          {forced.map((f) => (\n            <span key={f.note} className=\"flex flex-col items-center gap-1.5\">\n              <span aria-hidden=\"true\" className={`${btn(f.variant)} pointer-events-none ${f.cls}`}>{f.label}</span>\n              <span className=\"text-[11px] font-medium text-slate-600\">{f.note}</span>\n            </span>\n          ))}\n        </Row>\n        <Row label=\"Loading and disabled\">\n          <SaveButton />\n          <button type=\"button\" aria-busy=\"true\" aria-disabled=\"true\" className={`${btn(\"outline\")} pointer-events-none text-slate-600`}><Spinner />Uploading</button>\n          <button type=\"button\" disabled className={btn(\"primary\")}>Disabled</button>\n          <button type=\"button\" disabled className={btn(\"outline\")}>Disabled</button>\n        </Row>\n      </div>\n      <p className=\"mx-auto mt-5 max-w-[52rem] text-center text-[13px] text-slate-600\">Tab through to see focus rings. Press any button to feel it give.</p>\n    </div>\n  );\n}\n"}]}
