Skip to content

Commit

Permalink
feat(theme): add tokyoNightDay theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 7, 2022
1 parent e67f5ee commit 6f5a908
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 11 deletions.
1 change: 1 addition & 0 deletions core/README.md
Expand Up @@ -76,6 +76,7 @@ npm install @uiw/react-codemirror --save
| `@uiw/codemirror-theme-sublime` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-sublime.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-sublime.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/sublime) |
| `@uiw/codemirror-theme-tokyo-night` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night) |
| `@uiw/codemirror-theme-tokyo-night-storm` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-storm.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-storm) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night-storm.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-storm) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-storm) |
| `@uiw/codemirror-theme-tokyo-night-day` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-day.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-day) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night-day.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-day) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-day) |
| `@uiw/codemirror-theme-vscode` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-vscode.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-vscode) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-vscode.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-vscode) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/vscode) |
| `@uiw/codemirror-theme-xcode` | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-xcode.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-xcode) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-xcode.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-xcode) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/xcode) |

Expand Down
2 changes: 2 additions & 0 deletions themes/all/README.md
Expand Up @@ -78,6 +78,8 @@ export * from '@uiw/codemirror-theme-okaidia';
export * from '@uiw/codemirror-theme-solarized';
export * from '@uiw/codemirror-theme-sublime';
export * from '@uiw/codemirror-theme-tokyo-night';
export * from '@uiw/codemirror-theme-tokyo-night-storm';
export * from '@uiw/codemirror-theme-tokyo-night-day';
export * from '@uiw/codemirror-theme-vscode';
export * from '@uiw/codemirror-theme-xcode';
```
Expand Down
1 change: 1 addition & 0 deletions themes/all/package.json
Expand Up @@ -41,6 +41,7 @@
"@uiw/codemirror-theme-sublime": "4.18.2",
"@uiw/codemirror-theme-tokyo-night": "4.18.2",
"@uiw/codemirror-theme-tokyo-night-storm": "4.18.2",
"@uiw/codemirror-theme-tokyo-night-day": "4.18.2",
"@uiw/codemirror-theme-vscode": "4.18.2",
"@uiw/codemirror-theme-xcode": "4.18.2",
"@uiw/codemirror-themes": "4.18.2"
Expand Down
1 change: 1 addition & 0 deletions themes/all/src/index.ts
Expand Up @@ -18,5 +18,6 @@ export * from '@uiw/codemirror-theme-solarized';
export * from '@uiw/codemirror-theme-sublime';
export * from '@uiw/codemirror-theme-tokyo-night';
export * from '@uiw/codemirror-theme-tokyo-night-storm';
export * from '@uiw/codemirror-theme-tokyo-night-day';
export * from '@uiw/codemirror-theme-vscode';
export * from '@uiw/codemirror-theme-xcode';
12 changes: 12 additions & 0 deletions themes/theme/README.md
Expand Up @@ -244,6 +244,18 @@ export default App;
<img width="436" alt="codemirror-theme-tokyo-night" src="https://user-images.githubusercontent.com/1680273/206094521-c3a51de1-8cb7-4f01-a9bd-6cfd04a3aa0d.png">
</a>

**tokyo-night-day**

<a href="https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-day">
<img width="436" alt="codemirror-theme-tokyo-night-day" src="https://user-images.githubusercontent.com/1680273/206104544-ca4db2e0-caac-4804-9321-c269fe660245.png">
</a>

**tokyo-night-storm**

<a href="https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-storm">
<img width="436" alt="codemirror-theme-tokyo-night-storm" src="https://user-images.githubusercontent.com/1680273/206097179-8a490b97-87da-4285-a9bc-b0c9f510e7ed.png">
</a>

**vscode**

<a href="https://uiwjs.github.io/react-codemirror/#/theme/data/vscode/dark">
Expand Down
97 changes: 97 additions & 0 deletions themes/tokyo-night-day/README.md
@@ -0,0 +1,97 @@
<!--rehype:ignore:start-->

# TokyoNightDay Theme

<!--rehype:ignore:end-->

[![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-day.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-day)

<a href="https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-day">
<img width="436" alt="codemirror-theme-tokyo-night-day" src="https://user-images.githubusercontent.com/1680273/206104544-ca4db2e0-caac-4804-9321-c269fe660245.png">
</a>

## Install

```bash
npm install @uiw/codemirror-theme-tokyo-night-day --save
```

```jsx
import { tags as t } from '@lezer/highlight';
import { tokyoNightDay, tokyoNightDayInit } from '@uiw/codemirror-theme-tokyo-night-day';

<CodeMirror theme={tokyoNightDay} />
<CodeMirror
theme={tokyoNightDayInit({
settings: {
caret: '#c6c6c6',
fontFamily: 'monospace',
},
styles: [
{ tag: t.comment, color: '#6272a4' },
]
})}
/>
```

## API

```tsx
import { CreateThemeOptions } from '@uiw/codemirror-themes';
export declare const tokyoNightDayInit: (options?: CreateThemeOptions) => import('@codemirror/state').Extension;
export declare const tokyoNightDay: import('@codemirror/state').Extension;
```

## Usage

```jsx
import CodeMirror from '@uiw/react-codemirror';
import { tokyoNightDay } from '@uiw/codemirror-theme-tokyo-night-day';
import { javascript } from '@codemirror/lang-javascript';

function App() {
return (
<CodeMirror
value="console.log('hello world!');"
height="200px"
theme={tokyoNightDay}
extensions={[javascript({ jsx: true })]}
onChange={(value, viewUpdate) => {
console.log('value:', value);
}}
/>
);
}
export default App;
```

```js
import { EditorView } from '@codemirror/view';
import { EditorState } from '@codemirror/state';
import { javascript } from '@codemirror/lang-javascript';
import { tokyoNightDay } from '@uiw/codemirror-theme-tokyo-night-day';

const state = EditorState.create({
doc: 'my source code',
extensions: [tokyoNightDay, javascript({ jsx: true })],
});

const view = new EditorView({
parent: document.querySelector('#editor'),
state,
});
```

## Contributors

As always, thanks to our amazing contributors!

<a href="https://github.com/uiwjs/react-codemirror/graphs/contributors">
<img src="https://uiwjs.github.io/react-codemirror/CONTRIBUTORS.svg" />
</a>

Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors).

## License

Licensed under the MIT License.
42 changes: 42 additions & 0 deletions themes/tokyo-night-day/package.json
@@ -0,0 +1,42 @@
{
"name": "@uiw/codemirror-theme-tokyo-night-day",
"version": "4.18.2",
"description": "Theme tokyo-night-day for CodeMirror.",
"homepage": "https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-day",
"author": "kenny wong <wowohoo@qq.com>",
"license": "MIT",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"scripts": {
"watch": "tsbb watch",
"build": "tsbb build"
},
"repository": {
"type": "git",
"url": "https://github.com/uiwjs/react-codemirror.git"
},
"files": [
"src",
"esm",
"cjs"
],
"dependencies": {
"@uiw/codemirror-themes": "4.18.2"
},
"keywords": [
"codemirror",
"codemirror6",
"theme",
"tokyo-night",
"tokyo-night-day",
"syntax",
"ide",
"code"
],
"jest": {
"coverageReporters": [
"lcov",
"json-summary"
]
}
}
46 changes: 46 additions & 0 deletions themes/tokyo-night-day/src/index.ts
@@ -0,0 +1,46 @@
import { tags as t } from '@lezer/highlight';
import { createTheme, CreateThemeOptions } from '@uiw/codemirror-themes';

export const tokyoNightDayInit = (options?: CreateThemeOptions) => {
const { theme = 'light', settings = {}, styles = [] } = options || {};
return createTheme({
theme: theme,
settings: {
background: '#e1e2e7',
foreground: '#3760bf',
caret: '#3760bf',
selection: '#99a7df',
selectionMatch: '#99a7df',
gutterBackground: '#e1e2e7',
gutterForeground: '#3760bf',
gutterBorder: 'transparent',
lineHighlight: '#5f5faf11',
...settings,
},
styles: [
{ tag: t.keyword, color: '#007197' },
{ tag: [t.name, t.deleted, t.character, t.macroName], color: '#3760bf' },
{ tag: [t.propertyName], color: '#3760bf' },
{ tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)], color: '#587539' },
{ tag: [t.function(t.variableName), t.labelName], color: '#3760bf' },
{ tag: [t.color, t.constant(t.name), t.standard(t.name)], color: '#3760bf' },
{ tag: [t.definition(t.name), t.separator], color: '#3760bf' },
{ tag: [t.className], color: '#3760bf' },
{ tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace], color: '#b15c00' },
{ tag: [t.typeName], color: '#007197', fontStyle: '#007197' },
{ tag: [t.operator, t.operatorKeyword], color: '#007197' },
{ tag: [t.url, t.escape, t.regexp, t.link], color: '#587539' },
{ tag: [t.meta, t.comment], color: '#848cb5' },
{ tag: t.strong, fontWeight: 'bold' },
{ tag: t.emphasis, fontStyle: 'italic' },
{ tag: t.link, textDecoration: 'underline' },
{ tag: t.heading, fontWeight: 'bold', color: '#b15c00' },
{ tag: [t.atom, t.bool, t.special(t.variableName)], color: '#3760bf' },
{ tag: t.invalid, color: '#f52a65' },
{ tag: t.strikethrough, textDecoration: 'line-through' },
...styles,
],
});
};

export const tokyoNightDay = tokyoNightDayInit();
9 changes: 9 additions & 0 deletions themes/tokyo-night-day/tsconfig.json
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig",
"include": ["src"],
"compilerOptions": {
"outDir": "./cjs",
"baseUrl": ".",
"noEmit": false
}
}
2 changes: 1 addition & 1 deletion themes/tokyo-night-storm/README.md
Expand Up @@ -7,7 +7,7 @@
[![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-storm.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-storm)

<a href="https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-storm">
<img width="436" alt="codemirror-theme-tokyo-night-storm" src="https://user-images.githubusercontent.com/1680273/206094521-c3a51de1-8cb7-4f01-a9bd-6cfd04a3aa0d.png">
<img width="436" alt="codemirror-theme-tokyo-night-storm" src="https://user-images.githubusercontent.com/1680273/206097179-8a490b97-87da-4285-a9bc-b0c9f510e7ed.png">
</a>

## Install
Expand Down
1 change: 1 addition & 0 deletions www/package.json
Expand Up @@ -63,6 +63,7 @@
"@uiw/codemirror-theme-sublime": "4.18.2",
"@uiw/codemirror-theme-tokyo-night": "4.18.2",
"@uiw/codemirror-theme-tokyo-night-storm": "4.18.2",
"@uiw/codemirror-theme-tokyo-night-day": "4.18.2",
"@uiw/codemirror-theme-vscode": "4.18.2",
"@uiw/codemirror-theme-xcode": "4.18.2",
"@uiw/codemirror-themes": "4.18.2",
Expand Down
2 changes: 1 addition & 1 deletion www/src/index.tsx
Expand Up @@ -75,7 +75,7 @@ root.render(
<Route index element={<ThemesHome />} />
<Route path="data" element={<Navigate to="sublime" replace />} />
<Route path="data/:name" element={<ThemeOkaidia />} />
<Route path="data/:name/:lightOrDark" element={<ThemeOkaidia />} />
<Route path="data/:name/*" element={<ThemeOkaidia />} />
<Route path="editor" element={<Navigate to="single" replace />} />
<Route path="editor/:type" element={<ThemeEditor />} />
<Route path="doc" element={<ThemeDoc />} />
Expand Down
6 changes: 6 additions & 0 deletions www/src/pages/theme/themes/Datas.ts
Expand Up @@ -17,6 +17,8 @@ import eclipseMd from '@uiw/codemirror-theme-eclipse/README.md';
import bespinMd from '@uiw/codemirror-theme-bespin/README.md';
import sublimeMd from '@uiw/codemirror-theme-sublime/README.md';
import tokyoNightMd from '@uiw/codemirror-theme-tokyo-night/README.md';
import tokyoNightStormMd from '@uiw/codemirror-theme-tokyo-night-storm/README.md';
import tokyoNightDayMd from '@uiw/codemirror-theme-tokyo-night-day/README.md';
import vscodeMd from '@uiw/codemirror-theme-vscode/README.md';
import xcodeMd from '@uiw/codemirror-theme-xcode/README.md';

Expand All @@ -41,6 +43,7 @@ import { solarizedLight, solarizedDark } from '@uiw/codemirror-theme-solarized';
import { sublime } from '@uiw/codemirror-theme-sublime';
import { tokyoNight } from '@uiw/codemirror-theme-tokyo-night';
import { tokyoNightStorm } from '@uiw/codemirror-theme-tokyo-night-storm';
import { tokyoNightDay } from '@uiw/codemirror-theme-tokyo-night-day';
import { xcodeLight, xcodeDark } from '@uiw/codemirror-theme-xcode';

export const mdSource = {
Expand All @@ -67,6 +70,8 @@ export const mdSource = {
solarizedDark: solarizedMd.source,
sublime: sublimeMd.source,
tokyoNight: tokyoNightMd.source,
tokyoNightStorm: tokyoNightStormMd.source,
tokyoNightDay: tokyoNightDayMd.source,
vscodeDark: vscodeMd.source,
xcodeLight: xcodeMd.source,
xcodeDark: xcodeMd.source,
Expand Down Expand Up @@ -97,6 +102,7 @@ export const themeData = {
sublime,
tokyoNight,
tokyoNightStorm,
tokyoNightDay,
vscodeDark,
xcodeLight,
xcodeDark,
Expand Down
10 changes: 8 additions & 2 deletions www/src/pages/theme/themes/Document.tsx
Expand Up @@ -48,12 +48,18 @@ export const Document: FC<PropsWithChildren<DocumentProps>> = ({ children, theme
}
}, [themeName]);

const [_name] = toSnakeCase(themeName) || [];
let pkgName: string | undefined = themeName;
if (/(gruvbox)/i.test(themeName || '')) {
pkgName = themeName?.replace(/\s+?(dark|light)/gi, ' dark');
} else {
pkgName = themeName?.replace(/\s+?(dark|light)/gi, '');
}
const _name = toSnakeCase(pkgName || '') || [];
return (
<Warpper>
<Header>
<Title>{themeName} Theme</Title>
<PreCode value={`npm install @uiw/codemirror-theme-${_name} --save`} />
<PreCode value={`npm install @uiw/codemirror-theme-${_name.join('-')} --save`} />
<div>
<Button onClick={() => setPreviewDoc(!previewDoc)}>
{previewDoc ? 'Preview Theme' : 'Preview Document'}
Expand Down
13 changes: 10 additions & 3 deletions www/src/pages/theme/themes/SiderMenus.tsx
Expand Up @@ -27,10 +27,17 @@ export function SiderMenus() {
<Sider>
<MenuItem to={`/theme/`}>Home</MenuItem>
{Object.keys(themeData).map((name, key) => {
const [_name, _theme] = toSnakeCase(name) || [];
const [_name, _theme, ...other] = toSnakeCase(name) || [];
const title = [_name, _theme, ...other]
.filter(Boolean)
.map((item) => item?.slice(0, 1).toUpperCase() + item?.slice(1).toLowerCase())
.join(' ');
return (
<MenuItem key={key} to={`/theme/data/${_name}${_theme ? `/${_theme}` : ''}`}>
{_name} {_theme}
<MenuItem
key={key}
to={`/theme/data/${_name}${_theme ? `/${_theme}` : ''}${other ? `/${other.join('/')}` : ''}`}
>
{title}
</MenuItem>
);
})}
Expand Down
20 changes: 16 additions & 4 deletions www/src/pages/theme/themes/index.tsx
Expand Up @@ -5,14 +5,26 @@ import { Sample } from './Sample';
import { themeData } from './Datas';
import { SiderMenus } from './SiderMenus';

export const toCamelCase = (str: string = '') => {
const s =
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
?.map((x) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
.join('') || '';
return s.slice(0, 1).toLowerCase() + s.slice(1);
};

export const ThemeOkaidia = () => {
const { name = '', lightOrDark = '' } = useParams();
const text = name + lightOrDark.replace(lightOrDark[0], (lightOrDark[0] || '').toLocaleUpperCase());
const theme = themeData[text as keyof typeof themeData];
const { name = '', ...other } = useParams();
const textName = (name + '/' + (other['*'] || ''))
.split('/')
.filter(Boolean)
.map((item) => item?.slice(0, 1).toUpperCase() + item?.slice(1).toLowerCase());
const theme = themeData[toCamelCase(textName.join(' ')) as keyof typeof themeData];
return (
<Fragment>
<SiderMenus />
<Document themeName={text}>
<Document themeName={textName.join(' ')}>
<Sample theme={theme} />
</Document>
</Fragment>
Expand Down

0 comments on commit 6f5a908

Please sign in to comment.