@lightsparkdev/ui 0.0.11 → 0.0.12

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @lightsparkdev/ui
2
2
 
3
+ ## 0.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 15d0720: - Add CodeBlock
8
+ - 15d0720: - Consolidate type utils from ui to core
9
+ - Updated dependencies [15d0720]
10
+ - Updated dependencies [15d0720]
11
+ - @lightsparkdev/core@1.0.21
12
+
3
13
  ## 0.0.11
4
14
 
5
15
  ### Patch Changes
@@ -0,0 +1,198 @@
1
+ import {
2
+ CopyToClipboardButton
3
+ } from "./chunk-7C4MHI6Q.js";
4
+ import {
5
+ overflowAutoWithoutScrollbars
6
+ } from "./chunk-FCZJILMW.js";
7
+ import {
8
+ standardBorderRadius
9
+ } from "./chunk-JK4BP73A.js";
10
+ import {
11
+ colors,
12
+ themeOr
13
+ } from "./chunk-2VBDEO6M.js";
14
+ import {
15
+ __spreadProps,
16
+ __spreadValues
17
+ } from "./chunk-CIGAQ47A.js";
18
+
19
+ // src/components/CodeBlock.tsx
20
+ import styled from "@emotion/styled";
21
+ import Prism from "prismjs";
22
+ import "prismjs/components/prism-dart.min.js";
23
+ import "prismjs/components/prism-go.min.js";
24
+ import "prismjs/components/prism-graphql.min.js";
25
+ import "prismjs/components/prism-java.min.js";
26
+ import "prismjs/components/prism-json.min.js";
27
+ import "prismjs/components/prism-jsx.min.js";
28
+ import "prismjs/components/prism-kotlin.min.js";
29
+ import "prismjs/components/prism-python.min.js";
30
+ import "prismjs/components/prism-rust.min.js";
31
+ import "prismjs/components/prism-swift.min.js";
32
+ import "prismjs/themes/prism-tomorrow.css";
33
+ import { useLayoutEffect } from "react";
34
+ import Select from "react-select";
35
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
36
+ var ProgrammingLanguageOptions = {
37
+ Bash: "bash",
38
+ Flutter: "dart",
39
+ Go: "go",
40
+ GraphQL: "graphql",
41
+ Java: "java",
42
+ JavaScript: "js",
43
+ JSON: "json",
44
+ Kotlin: "kotlin",
45
+ Python: "python",
46
+ React: "react",
47
+ ReactNative: "tsx",
48
+ Rust: "rust",
49
+ Swift: "swift",
50
+ Text: "txt"
51
+ };
52
+ var backgroundColor = "#2d2d2d";
53
+ var InlineCode = styled.span`
54
+ font-family: "Roboto Mono", monospace;
55
+ background-color: #2d2d2d;
56
+ border: 1px solid ${themeOr(colors.gray90, colors.gray20)};
57
+ border-radius: 3px;
58
+ line-height: 24px;
59
+ padding: 0 4px;
60
+ `;
61
+ var codeSelectStyles = {
62
+ container: (styles) => __spreadProps(__spreadValues({}, styles), {
63
+ display: "flex"
64
+ }),
65
+ control: (styles) => __spreadProps(__spreadValues({}, styles), {
66
+ backgroundColor,
67
+ border: "none",
68
+ cursor: "pointer",
69
+ "&:hover": {
70
+ border: "#none"
71
+ },
72
+ boxShadow: "none",
73
+ minHeight: 0
74
+ }),
75
+ dropdownIndicator: (styles) => __spreadProps(__spreadValues({}, styles), {
76
+ color: "#ffffff",
77
+ padding: "0 0 0 4px",
78
+ "&:hover": {
79
+ color: "#ffffff"
80
+ }
81
+ }),
82
+ indicatorSeparator: (styles) => ({
83
+ display: "none"
84
+ }),
85
+ input: (styles) => __spreadProps(__spreadValues({}, styles), {
86
+ fontSize: "1rem",
87
+ margin: 0,
88
+ color: "transparent"
89
+ }),
90
+ menu: (styles) => __spreadProps(__spreadValues({}, styles), {
91
+ backgroundColor,
92
+ width: "auto"
93
+ }),
94
+ menuList: (styles) => __spreadProps(__spreadValues({}, styles), {
95
+ borderRadius: "4px",
96
+ padding: 0
97
+ }),
98
+ option: (styles, state) => __spreadProps(__spreadValues({}, styles), {
99
+ cursor: "pointer",
100
+ backgroundColor: state.isSelected ? colors.gray25 : backgroundColor,
101
+ "&:hover": {
102
+ backgroundColor: colors.gray25
103
+ }
104
+ }),
105
+ singleValue: (styles) => __spreadProps(__spreadValues({}, styles), {
106
+ color: "#ffffff",
107
+ margin: 0
108
+ }),
109
+ valueContainer: (styles) => __spreadProps(__spreadValues({}, styles), {
110
+ padding: 0
111
+ })
112
+ };
113
+ var CodeBlock = ({
114
+ title,
115
+ children,
116
+ className,
117
+ language = "Text",
118
+ languageOptions,
119
+ onSelectLanguage,
120
+ withCopyButton
121
+ }) => {
122
+ useLayoutEffect(() => {
123
+ Prism.highlightAll();
124
+ }, [children, language]);
125
+ const header = withCopyButton || languageOptions && onSelectLanguage ? /* @__PURE__ */ jsxs(CodeBlockHeader, { children: [
126
+ title && /* @__PURE__ */ jsx(CodeBlockHeaderTitle, { children: title }),
127
+ /* @__PURE__ */ jsxs(
128
+ "div",
129
+ {
130
+ css: {
131
+ display: "flex",
132
+ alignItems: "center",
133
+ justifyContent: title ? "flex-end" : "space-between",
134
+ width: "100%"
135
+ },
136
+ children: [
137
+ languageOptions && onSelectLanguage ? /* @__PURE__ */ jsx("div", { css: { margin: title ? "0 16px 0 auto" : "0" }, children: /* @__PURE__ */ jsx(
138
+ Select,
139
+ {
140
+ value: { value: language, label: language },
141
+ options: languageOptions.map((lang) => ({
142
+ value: lang,
143
+ label: lang
144
+ })),
145
+ onChange: (selected) => {
146
+ if (selected == null ? void 0 : selected.value) {
147
+ onSelectLanguage(selected.value);
148
+ }
149
+ },
150
+ styles: codeSelectStyles
151
+ }
152
+ ) }) : null,
153
+ withCopyButton ? /* @__PURE__ */ jsx(CopyToClipboardButton, { value: children }) : null
154
+ ]
155
+ }
156
+ )
157
+ ] }) : null;
158
+ return /* @__PURE__ */ jsxs(StyledCodeBlock, { className, children: [
159
+ header,
160
+ /* @__PURE__ */ jsx(CodeBlockContainer, { hasHeader: header !== null, children: /* @__PURE__ */ jsx("code", { className: `language-${ProgrammingLanguageOptions[language]}`, children }) })
161
+ ] });
162
+ };
163
+ var StyledCodeBlock = styled.div``;
164
+ var CodeBlockHeader = styled.div`
165
+ align-items: center;
166
+ background-color: #2d2d2d;
167
+ border-bottom: 1px solid ${colors.gray25};
168
+ border-top-left-radius: 8px;
169
+ border-top-right-radius: 8px;
170
+ color: #ffffff;
171
+ display: flex;
172
+ flex-direction: row;
173
+ justify-content: space-between;
174
+ padding: 16px 20px;
175
+ `;
176
+ var CodeBlockContainer = styled.pre`
177
+ ${overflowAutoWithoutScrollbars}
178
+ &[class*="language-"] {
179
+ padding: 20px;
180
+ font-weight: 500;
181
+ ${standardBorderRadius(8)}
182
+ ${(props) => props.hasHeader ? `border-top-left-radius: 0;
183
+ border-top-right-radius: 0;
184
+ margin-top: 0;` : ""}
185
+ }
186
+ `;
187
+ var CodeBlockHeaderTitle = styled.div`
188
+ width: 100%;
189
+ font-weight: 500;
190
+ color: ${({ theme }) => theme.hcNeutralFromBg(backgroundColor)};
191
+ `;
192
+
193
+ export {
194
+ ProgrammingLanguageOptions,
195
+ InlineCode,
196
+ CodeBlock,
197
+ StyledCodeBlock
198
+ };