Skip to content

Commit f61ca2e

Browse files
committed
feat: useAllDefaultValues and customTheme
1 parent e446999 commit f61ca2e

File tree

9 files changed

+419
-121
lines changed

9 files changed

+419
-121
lines changed

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ console.log(conversionResult);
4848

4949
### `TranslatorConfig`
5050

51-
| Attribute | Description | Type |
52-
| :-------: | :--------------------------------------------------------------------------------: | :----: |
53-
| `prefix` | [tailwind configuration prefix](https://tailwindcss.com/docs/configuration#prefix) | string |
51+
| Attribute | Description | Type |
52+
| :-------------------: | :--------------------------------------------------------------------------------: | :-------------------------: |
53+
| `prefix` | [tailwind configuration prefix](https://tailwindcss.com/docs/configuration#prefix) | string |
54+
| `useAllDefaultValues` | Use tailwind all default values(The default is false) | boolean |
55+
| `customTheme` | Custom conversion of preset property values | [CustomTheme](#customtheme) |
56+
57+
### `CustomTheme`
58+
59+
```typescript
60+
export interface CustomTheme
61+
extends Record<string, undefined | Record<string, string>> {
62+
media?: Record<string, string>;
63+
"backdrop-blur"?: Record<string, string>;
64+
"backdrop-brightness"?: Record<string, string>;
65+
"backdrop-contrast"?: Record<string, string>;
66+
"backdrop-grayscale"?: Record<string, string>;
67+
"backdrop-hue-rotate"?: Record<string, string>;
68+
"backdrop-invert"?: Record<string, string>;
69+
"backdrop-opacity"?: Record<string, string>;
70+
"backdrop-saturate"?: Record<string, string>;
71+
"backdrop-sepia"?: Record<string, string>;
72+
blur?: Record<string, string>;
73+
brightness?: Record<string, string>;
74+
contrast?: Record<string, string>;
75+
grayscale?: Record<string, string>;
76+
"hue-rotate"?: Record<string, string>;
77+
invert?: Record<string, string>;
78+
saturate?: Record<string, string>;
79+
sepia?: Record<string, string>;
80+
scale?: Record<string, string>;
81+
rotate?: Record<string, string>;
82+
translate?: Record<string, string>;
83+
skew?: Record<string, string>;
84+
// custom more...
85+
}
86+
```

components/ResultSection.tsx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Editor from '@monaco-editor/react'
12
import clsx from 'clsx'
23
import { useState } from 'react'
34
import FlipMove from 'react-flip-move'
@@ -10,23 +11,48 @@ import { copyText } from '@/utils/index'
1011
function ResultSection(props: {
1112
themeChange: () => void
1213
isDarkTheme?: boolean
13-
prefix: string
14-
setPrefix: (v: string) => void
14+
config: TranslatorConfigCopy
15+
setConfig: (v: TranslatorConfigCopy) => void
1516
computedResultVals: ComputedResultCode[]
1617
}) {
17-
const { themeChange, isDarkTheme, computedResultVals, prefix, setPrefix } = props
18+
const { themeChange, isDarkTheme, computedResultVals, config, setConfig } = props
1819
const [configShow, setConfigShow] = useState<boolean>(false)
1920
return (
2021
<section className='font-[Consolas,_"Courier_New",_monospace] lgx:col-start-2 relative lgx:h-full max-lgx:h-1/2 overflow-y-auto text-[#111827] dark:text-[#abb2bf]'>
2122
<div className="absolute right-[16px] top-[16px] flex items-center">
2223
<div className="mr-[16px] relative z-10">
23-
<button onClick={() => setConfigShow(v => !v)} className="h-[32px] rounded-[16px] px-[12px] text-[18px] font-bold border-solid border-[1px] dark:border-[rgba(82,82,89,.68)] dark:bg-[#313136] border-[rgba(60,60,67,.29)] bg-[#eeeeee] filter hover:brightness-105 active:enabled:brightness-95">
24+
<button onClick={() => setConfigShow(v => !v)} className="h-[32px] rounded-[16px] px-[12px] text-[16px] font-bold border-solid border-[1px] dark:border-[rgba(82,82,89,.68)] dark:bg-[#313136] border-[rgba(60,60,67,.29)] bg-[#eeeeee] filter hover:brightness-105 active:enabled:brightness-95">
2425
SetConfig
2526
</button>
26-
<ul className={clsx('absolute right-[0] -bottom-[16px] transform translate-y-full dark:border-[#454545] border-[#c8c8c8] border-solid border-[1px] dark:bg-[#1e1e1e] bg-[#f3f3f3] rounded-[8px] p-[16px]', configShow ? 'opacity-100' : 'opacity-0 pointer-events-none')}>
27-
<li className="flex items-center">
27+
<ul className={clsx('absolute left-1/2 -bottom-[16px] transform translate-y-full -translate-x-1/2 dark:border-[#454545] border-[#c8c8c8] border-solid border-[1px] dark:bg-[#1e1e1e] bg-[#f3f3f3] rounded-[8px] pt-[16px] px-[16px] pb-[8px] before:content-[""] before:w-[8px] before:h-[8px] before:bg-inherit before:block before:absolute before:-top-[4px] before:[border:inherit] before:!border-b-transparent before:!border-r-transparent before:left-1/2 before:transform before:-translate-x-1/2 before:rotate-45 [&>li]:mb-[8px]', configShow ? 'opacity-100' : 'opacity-0 pointer-events-none')}>
28+
<li className="flex items-center w-[300px]">
2829
<span>prefix:</span>
29-
<input value={prefix} onChange={e => setPrefix(e.target.value)} type="text" className="ml-[8px] py-[2px] px-[4px] dark:bg-[#0f0f0f] bg-[#ffffff] rounded-[4px] text-inherit" />
30+
<input value={config.prefix} onChange={e => setConfig({ ...config, prefix: e.target.value })} type="text" className="w-[220px] ml-[8px] py-[2px] px-[4px] dark:bg-[#0f0f0f] bg-[#ffffff] rounded-[4px] text-inherit outline-none border-[1px] border-solid border-transparent dark:focus:border-[#f3f3f3] focus:border-[#454545]" />
31+
</li>
32+
<li className="flex items-center">
33+
<span>useAllDefaultValues:</span>
34+
<input checked={config.useAllDefaultValues} onChange={e => setConfig({ ...config, useAllDefaultValues: e.target.checked })} type="checkbox" className="w-[20px] h-[20px] ml-[8px]" />
35+
</li>
36+
<li className="flex flex-col">
37+
<span>customTheme:</span>
38+
<div>
39+
<Editor
40+
className="text-inherit outline-none border-[1px] border-solid dark:border-[#454545] border-[#c8c8c8]"
41+
width={'100%'}
42+
height={300}
43+
language="json"
44+
theme={isDarkTheme ? 'vs-dark' : 'light'}
45+
onChange={v => setConfig({ ...config, customTheme: v ?? '' })}
46+
defaultValue={config.customTheme}
47+
options={{
48+
fontSize: 18,
49+
lineNumbers: 'off',
50+
minimap: {
51+
enabled: false
52+
}
53+
}}
54+
/>
55+
</div>
3056
</li>
3157
</ul>
3258
</div>

0 commit comments

Comments
 (0)