2
0

react.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React from "react"
  2. interface VSCodeProps {
  3. children?: React.ReactNode
  4. onClick?: () => void
  5. onChange?: (e: any) => void
  6. onInput?: (e: any) => void
  7. appearance?: string
  8. checked?: boolean
  9. value?: string | number
  10. placeholder?: string
  11. href?: string
  12. "data-testid"?: string
  13. style?: React.CSSProperties
  14. slot?: string
  15. role?: string
  16. disabled?: boolean
  17. className?: string
  18. title?: string
  19. }
  20. export const VSCodeButton: React.FC<VSCodeProps> = ({ children, onClick, appearance, className, ...props }) => {
  21. // For icon buttons, render children directly without any wrapping
  22. if (appearance === "icon") {
  23. return React.createElement(
  24. "button",
  25. {
  26. onClick,
  27. className: `${className || ""}`,
  28. "data-appearance": appearance,
  29. ...props,
  30. },
  31. children,
  32. )
  33. }
  34. // For regular buttons
  35. return React.createElement(
  36. "button",
  37. {
  38. onClick,
  39. className: className,
  40. ...props,
  41. },
  42. children,
  43. )
  44. }
  45. export const VSCodeCheckbox: React.FC<VSCodeProps> = ({ children, onChange, checked, ...props }) =>
  46. React.createElement("label", {}, [
  47. React.createElement("input", {
  48. key: "input",
  49. type: "checkbox",
  50. checked,
  51. onChange: (e: any) => onChange?.({ target: { checked: e.target.checked } }),
  52. "aria-label": typeof children === "string" ? children : undefined,
  53. ...props,
  54. }),
  55. children && React.createElement("span", { key: "label" }, children),
  56. ])
  57. export const VSCodeTextField: React.FC<VSCodeProps> = ({ children, value, onInput, placeholder, ...props }) =>
  58. React.createElement("div", { style: { position: "relative", display: "inline-block", width: "100%" } }, [
  59. React.createElement("input", {
  60. key: "input",
  61. type: "text",
  62. value,
  63. onChange: (e: any) => onInput?.({ target: { value: e.target.value } }),
  64. placeholder,
  65. ...props,
  66. }),
  67. children,
  68. ])
  69. export const VSCodeTextArea: React.FC<VSCodeProps> = ({ value, onChange, ...props }) =>
  70. React.createElement("textarea", {
  71. value,
  72. onChange: (e: any) => onChange?.({ target: { value: e.target.value } }),
  73. ...props,
  74. })
  75. export const VSCodeLink: React.FC<VSCodeProps> = ({ children, href, ...props }) =>
  76. React.createElement("a", { href: href || "#", ...props }, children)
  77. export const VSCodeDropdown: React.FC<VSCodeProps> = ({ children, value, onChange, ...props }) =>
  78. React.createElement("select", { value, onChange, ...props }, children)
  79. export const VSCodeOption: React.FC<VSCodeProps> = ({ children, value, ...props }) =>
  80. React.createElement("option", { value, ...props }, children)
  81. export const VSCodeRadio: React.FC<VSCodeProps> = ({ children, value, checked, onChange, ...props }) =>
  82. React.createElement("label", { style: { display: "inline-flex", alignItems: "center" } }, [
  83. React.createElement("input", {
  84. key: "input",
  85. type: "radio",
  86. value,
  87. checked,
  88. onChange,
  89. ...props,
  90. }),
  91. children && React.createElement("span", { key: "label", style: { marginLeft: "4px" } }, children),
  92. ])
  93. export const VSCodeRadioGroup: React.FC<VSCodeProps> = ({ children, onChange, ...props }) =>
  94. React.createElement("div", { role: "radiogroup", onChange, ...props }, children)