Skip to content

Commit

Permalink
feat: list checkbox syle
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 18, 2024
1 parent 409306b commit 8f95b76
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
// ["tw\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]

["tw`([^`]*)`", "([^`]*)"]
],

// If you do not want to autofix some rules on save
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/dx-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
globalThis.tw = function tw(strings: TemplateStringsArray, ...values: any[]) {
return strings.reduce((acc, str, i) => {
const value = values[i] ?? ""
return acc + str + value
}, "")
}
1 change: 1 addition & 0 deletions src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</div>
</div>

<script type="module" src="./dx-helper.ts"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions src/renderer/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare global {
export interface Window {
SENTRY_RELEASE: typeof SENTRY_RELEASE
}

export function tw(strings: TemplateStringsArray, ...values: any[]): string
}

export {}
15 changes: 15 additions & 0 deletions src/renderer/src/lib/parse-html.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Checkbox } from "@renderer/components/ui/checkbox"
import { ShikiHighLighter } from "@renderer/components/ui/code-highlighter"
import { Image } from "@renderer/components/ui/image"
import { LinkWithTooltip } from "@renderer/components/ui/link"
Expand Down Expand Up @@ -90,6 +91,20 @@ export const parseHtml = async (
}
return createElement("p", undefined, props.children)
},
hr: ({ node, ...props }) => createElement("hr", {
...props,
className: tw`scale-x-50`,
}),
input: ({ node, ...props }) => {
if (props.type === "checkbox") {
return createElement(Checkbox, {
...props,
disabled: false,
className: tw`pointer-events-none mr-2`,
})
}
return createElement("input", props)
},
pre: ({ node, ...props }) => {
if (!props.children) return null

Expand Down

0 comments on commit 8f95b76

Please sign in to comment.