-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): add
console
theme (#632)
* feat: add `console` theme * chore: add readme to new theme and root
- Loading branch information
Showing
10 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!--rehype:ignore:start--> | ||
|
||
# Console Theme (dark/light) | ||
|
||
<!--rehype:ignore:end--> | ||
|
||
[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) | ||
[![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-console.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-console) | ||
|
||
<!--missing images--> | ||
|
||
## Motivation | ||
|
||
One of the usages for react-codemirror is a logger component, but there is no theme with the required styles for achieving the desired feature. This theme is intended to be used when you want to have plain text in a console or terminal viewer. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @uiw/codemirror-theme-console --save | ||
``` | ||
|
||
```jsx | ||
import { consoleLight, consoleLightInit, consoleDark, consoleDarkInit } from '@uiw/codemirror-theme-console'; | ||
// Or | ||
import { consoleDark, consoleDarkInit } from '@uiw/codemirror-theme-console/dark'; | ||
import { consoleLight, consoleLightInit } from '@uiw/codemirror-theme-console/light'; | ||
|
||
<CodeMirror theme={consoleLight} /> | ||
<CodeMirror | ||
theme={consoleLightInit({ | ||
settings: { | ||
caret: '#c6c6c6', | ||
fontFamily: 'monospace', | ||
} | ||
})} | ||
/> | ||
``` | ||
|
||
## API | ||
|
||
```tsx | ||
import { CreateThemeOptions } from '@uiw/codemirror-themes'; | ||
export declare const defaultSettingsConsoleLight: CreateThemeOptions['settings']; | ||
export declare const consoleLightInit: (options?: Partial<CreateThemeOptions>) => import('@codemirror/state').Extension; | ||
export declare const consoleLight: import('@codemirror/state').Extension; | ||
export declare const defaultSettingsConsoleDark: CreateThemeOptions['settings']; | ||
export declare const consoleDarkInit: (options?: Partial<CreateThemeOptions>) => import('@codemirror/state').Extension; | ||
export declare const consoleDark: import('@codemirror/state').Extension; | ||
``` | ||
|
||
## Usage | ||
|
||
```jsx | ||
import CodeMirror from '@uiw/react-codemirror'; | ||
import { consoleLight, consoleDark } from '@uiw/codemirror-theme-console'; | ||
import { javascript } from '@codemirror/lang-javascript'; | ||
|
||
function App() { | ||
return ( | ||
<CodeMirror | ||
value="INFO:waitress:Serving on http://0.0.0.0:5000" | ||
height="200px" | ||
theme={consoleLight} | ||
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 { consoleLight, consoleDark } from '@uiw/codemirror-theme-console'; | ||
|
||
const state = EditorState.create({ | ||
doc: 'my source code', | ||
extensions: [consoleDark], | ||
}); | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module '@uiw/codemirror-theme-console/dark' { | ||
import { CreateThemeOptions } from '@uiw/codemirror-themes'; | ||
export const defaultSettingsConsoleDark: CreateThemeOptions['settings']; | ||
export const consoleDarkInit: (options?: Partial<CreateThemeOptions>) => import('@codemirror/state').Extension; | ||
export const consoleDark: import('@codemirror/state').Extension; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module '@uiw/codemirror-theme-console/light' { | ||
import { CreateThemeOptions } from '@uiw/codemirror-themes'; | ||
export const defaultSettingsConsoleLight: CreateThemeOptions['settings']; | ||
export const consoleLightInit: (options?: Partial<CreateThemeOptions>) => import('@codemirror/state').Extension; | ||
export const consoleLight: import('@codemirror/state').Extension; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "@uiw/codemirror-theme-console", | ||
"version": "1.0.0", | ||
"description": "Theme console for CodeMirror.", | ||
"homepage": "https://uiwjs.github.io/react-codemirror/#/theme/data/console/light", | ||
"author": "David Villamarin <[email protected]>", | ||
"license": "MIT", | ||
"main": "./cjs/index.js", | ||
"module": "./esm/index.js", | ||
"exports": { | ||
"./README.md": "./README.md", | ||
".": { | ||
"import": "./esm/index.js", | ||
"types": "./cjs/index.d.ts", | ||
"require": "./cjs/index.js" | ||
}, | ||
"./light": { | ||
"import": "./esm/light.js", | ||
"types": "./cjs/light.d.ts", | ||
"require": "./cjs/light.js" | ||
}, | ||
"./dark": { | ||
"import": "./esm/dark.js", | ||
"types": "./cjs/dark.d.ts", | ||
"require": "./cjs/dark.js" | ||
} | ||
}, | ||
"scripts": { | ||
"watch": "tsbb watch src/*.ts --use-babel", | ||
"build": "tsbb build src/*.ts --use-babel" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/uiwjs/react-codemirror.git" | ||
}, | ||
"files": [ | ||
"dark.d.ts", | ||
"light.d.ts", | ||
"src", | ||
"esm", | ||
"cjs" | ||
], | ||
"dependencies": { | ||
"@uiw/codemirror-themes": "4.21.21" | ||
}, | ||
"keywords": [ | ||
"codemirror", | ||
"codemirror6", | ||
"theme", | ||
"console", | ||
"syntax", | ||
"ide", | ||
"code" | ||
], | ||
"jest": { | ||
"coverageReporters": [ | ||
"lcov", | ||
"json-summary" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createTheme, CreateThemeOptions } from '@uiw/codemirror-themes'; | ||
|
||
export const defaultSettingsConsoleDark: CreateThemeOptions['settings'] = { | ||
background: '#000', | ||
foreground: '#fff', | ||
caret: '#fff', | ||
selection: '#3e4865', | ||
selectionMatch: '#2a3967', | ||
gutterBackground: '#000', | ||
gutterForeground: '#ada9a9', | ||
gutterActiveForeground: '#000', | ||
lineHighlight: '#828282', | ||
}; | ||
|
||
export const consoleDarkInit = (options?: Partial<CreateThemeOptions>) => { | ||
const { theme = 'dark', settings = {}, styles = [] } = options || {}; | ||
return createTheme({ | ||
theme: theme, | ||
settings: { | ||
...defaultSettingsConsoleDark, | ||
...settings, | ||
}, | ||
styles: [...styles], | ||
}); | ||
}; | ||
|
||
export const consoleDark = consoleDarkInit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './dark'; | ||
export * from './light'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createTheme, CreateThemeOptions } from '@uiw/codemirror-themes'; | ||
|
||
export const defaultSettingsConsoleLight: CreateThemeOptions['settings'] = { | ||
background: '#fff', | ||
foreground: '#000', | ||
caret: '#000', | ||
selection: '#d6ddf2', | ||
selectionMatch: '#6d85cf', | ||
gutterBackground: '#fff', | ||
gutterForeground: '#ada9a9', | ||
gutterActiveForeground: '#000', | ||
lineHighlight: '#c7c5c5', | ||
}; | ||
|
||
export const consoleLightInit = (options?: Partial<CreateThemeOptions>) => { | ||
const { theme = 'light', settings = {}, styles = [] } = options || {}; | ||
return createTheme({ | ||
theme: theme, | ||
settings: { | ||
...defaultSettingsConsoleLight, | ||
...settings, | ||
}, | ||
styles: [...styles], | ||
}); | ||
}; | ||
|
||
export const consoleLight = consoleLightInit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"outDir": "./cjs", | ||
"baseUrl": ".", | ||
"noEmit": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters