UNPKG

@uiw/codemirror-themes

Version:
386 lines (309 loc) 20.3 kB
<div markdown="1"> <sup>Using <a href="https://wangchujiang.com/#/app" target="_blank">my app</a> is also a way to <a href="https://wangchujiang.com/#/sponsor" target="_blank">support</a> me:</sup> <br> <a target="_blank" href="https://apps.apple.com/app/Vidwall/6747587746" title="Vidwall for macOS"><img align="center" alt="Vidwall" height="52" width="52" src="https://github.com/user-attachments/assets/7b5df70a-ed91-4d4b-85be-f00e60a09ce9"></a> <a target="_blank" href="https://wangchujiang.com/mousio-hint/" title="Mousio Hint for macOS"><img align="center" alt="Mousio Hint" height="52" width="52" src="https://github.com/user-attachments/assets/3c0af128-0cef-44e5-a8db-4741dc5a6690"></a> <a target="_blank" href="https://apps.apple.com/app/6746747327" title="Mousio for macOS"><img align="center" alt="Mousio" height="52" width="52" src="https://github.com/user-attachments/assets/9edf61ff-5a6c-4676-9cc2-8fd3c1ad0dfb"></a> <a target="_blank" href="https://apps.apple.com/app/6745227444" title="Musicer for macOS"><img align="center" alt="Musicer" height="52" width="52" src="https://github.com/user-attachments/assets/b7abfba8-88ff-4c86-a125-43073d5aef22"></a> <a target="_blank" href="https://apps.apple.com/app/6743841447" title="Audioer for macOS"><img align="center" alt="Audioer" height="52" width="52" src="https://github.com/user-attachments/assets/7a836865-8c90-4119-87bc-19e06a76c957"></a> <a target="_blank" href="https://apps.apple.com/app/6744690194" title="FileSentinel for macOS"><img align="center" alt="FileSentinel" height="52" width="52" src="https://github.com/user-attachments/assets/28bce2cc-290e-45bf-9068-585ff6ecafe9"></a> <a target="_blank" href="https://apps.apple.com/app/6743495172" title="FocusCursor for macOS"><img align="center" alt="FocusCursor" height="52" width="52" src="https://github.com/user-attachments/assets/d543668a-737b-4853-a6bb-eaa269e69836"></a> <a target="_blank" href="https://apps.apple.com/app/6742680573" title="Videoer for macOS"><img align="center" alt="Videoer" height="52" width="52" src="https://github.com/user-attachments/assets/10ffb0f1-0625-40d6-93f1-2c2496592595"></a> <a target="_blank" href="https://apps.apple.com/app/6740425504" title="KeyClicker for macOS"><img align="center" alt="KeyClicker" height="52" width="52" src="https://github.com/user-attachments/assets/5a19fcb9-cb81-4855-b4ea-31c604d9612a"></a> <a target="_blank" href="https://apps.apple.com/app/6739052447" title="DayBar for macOS"><img align="center" alt="DayBar" height="52" width="52" src="https://github.com/user-attachments/assets/771b608d-594c-492d-8532-d9231e383f5b"></a> <a target="_blank" href="https://apps.apple.com/app/6739444407" title="Iconed for macOS"><img align="center" alt="Iconed" height="52" width="52" src="https://github.com/user-attachments/assets/8a35dc7b-4faf-4e2a-9311-f66d6844a896"></a> <a target="_blank" href="https://apps.apple.com/app/6737160756" title="RightMenu Master for macOS"><img align="center" alt="RightMenu Master" height="52" width="52" src="https://github.com/user-attachments/assets/39a76541-71bf-4de7-a01c-c62f0557dff5"></a> <a target="_blank" href="https://apps.apple.com/app/6723903021" title="Paste Quick for macOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/bdaad5b7-9810-44ce-8f17-8410864465d2"></a> <a target="_blank" href="https://apps.apple.com/app/6670696072" title="Quick RSS for macOS/iOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/374106b5-a448-4d1d-9ccb-b04b6bc681ed"></a> <a target="_blank" href="https://apps.apple.com/app/6670167443" title="Web Serve for macOS"><img align="center" alt="Web Serve" height="52" width="52" src="https://github.com/user-attachments/assets/e1d9f76f-0f3d-4ba5-8a15-253ee173bb1c"></a> <a target="_blank" href="https://apps.apple.com/app/6503953628" title="Copybook Generator for macOS/iOS"><img align="center" alt="Copybook Generator" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/b90e42ff-158b-4534-82ca-5898fd0e8d73"></a> <a target="_blank" href="https://apps.apple.com/app/6471227008" title="DevTutor for macOS/iOS"><img align="center" alt="DevTutor for SwiftUI" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/f15c154d-0192-48eb-8e0e-9e245ffd974a"></a> <a target="_blank" href="https://apps.apple.com/app/6479819388" title="RegexMate for macOS/iOS"><img align="center" alt="RegexMate" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/aabe5aa9-9a96-4390-8bed-c3e4023d0dea"></a> <a target="_blank" href="https://apps.apple.com/app/6479194014" title="Time Passage for macOS/iOS"><img align="center" alt="Time Passage" height="52" width="52" src="https://github.com/jaywcjlove/time-passage/assets/1680273/6f30e429-e6f3-4dbe-9921-a5effe2a05e9"></a> <a target="_blank" href="https://apps.apple.com/app/6478772538" title="IconizeFolder for macOS"><img align="center" alt="Iconize Folder" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/fa9d8b9c-1e51-4ded-877c-fa5b21c47220"></a> <a target="_blank" href="https://apps.apple.com/app/6478511402" title="Textsound Saver for macOS/iOS"><img align="center" alt="Textsound Saver" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/0595e842-980b-4574-8891-a8ba853a08be"></a> <a target="_blank" href="https://apps.apple.com/app/6476924627" title="Create Custom Symbols for macOS"><img align="center" alt="Create Custom Symbols" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/8cd022ce-a3f1-4e89-b7c6-6fbd0d4db77c"></a> <a target="_blank" href="https://apps.apple.com/app/6476452351" title="DevHub for macOS"><img align="center" alt="DevHub" height="52" width="52" src="https://github.com/user-attachments/assets/4a44a4fd-67ce-430b-af0a-72f18feaa47d"></a> <a target="_blank" href="https://apps.apple.com/app/6476400184" title="Resume Revise for macOS"><img align="center" alt="Resume Revise" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c9954a20-1905-48de-bdf8-d71837974aa2"></a> <a target="_blank" href="https://apps.apple.com/app/6472593276" title="Palette Genius for macOS"><img align="center" alt="Palette Genius" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/27340413-d355-45b2-8f6f-6ac37682d957"></a> <a target="_blank" href="https://apps.apple.com/app/6470879005" title="Symbol Scribe for macOS"><img align="center" alt="Symbol Scribe" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c7249f05-fa70-4def-a1e9-571d5f171fc9"></a> <br><br> </div> <hr> # Custom Codemirror Themes [![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-themes.svg)](https://www.npmjs.com/package/@uiw/codemirror-themes) Themes for CodeMirror. ## Install ```bash npm install @uiw/codemirror-themes --save ``` ## Usage ```js import { EditorView } from '@codemirror/view'; import { EditorState } from '@codemirror/state'; import { createTheme } from '@uiw/codemirror-themes'; import { javascript } from '@codemirror/lang-javascript'; import { tags as t } from '@lezer/highlight'; const myTheme = createTheme({ theme: 'light', settings: { background: '#ffffff', backgroundImage: '', foreground: '#75baff', caret: '#5d00ff', selection: '#036dd626', selectionMatch: '#036dd626', lineHighlight: '#8a91991a', gutterBorder: '1px solid #ffffff10', gutterBackground: '#fff', gutterForeground: '#8a919966', }, styles: [ { tag: t.comment, color: '#787b8099' }, { tag: t.variableName, color: '#0080ff' }, { tag: [t.string, t.special(t.brace)], color: '#5c6166' }, { tag: t.number, color: '#5c6166' }, { tag: t.bool, color: '#5c6166' }, { tag: t.null, color: '#5c6166' }, { tag: t.keyword, color: '#5c6166' }, { tag: t.operator, color: '#5c6166' }, { tag: t.className, color: '#5c6166' }, { tag: t.definition(t.typeName), color: '#5c6166' }, { tag: t.typeName, color: '#5c6166' }, { tag: t.angleBracket, color: '#5c6166' }, { tag: t.tagName, color: '#5c6166' }, { tag: t.attributeName, color: '#5c6166' }, ], }); const state = EditorState.create({ doc: 'my source code', extensions: [myTheme, javascript({ jsx: true })], }); const view = new EditorView({ parent: document.querySelector('#editor'), state, }); ``` ```jsx import CodeMirror from '@uiw/react-codemirror'; import { createTheme } from '@uiw/codemirror-themes'; import { javascript } from '@codemirror/lang-javascript'; import { tags as t } from '@lezer/highlight'; const myTheme = createTheme({ theme: 'light', settings: { background: '#ffffff', backgroundImage: '', foreground: '#75baff', caret: '#5d00ff', selection: '#036dd626', selectionMatch: '#036dd626', lineHighlight: '#8a91991a', gutterBackground: '#fff', gutterForeground: '#8a919966', }, styles: [ { tag: t.comment, color: '#787b8099' }, { tag: t.variableName, color: '#0080ff' }, { tag: [t.string, t.special(t.brace)], color: '#5c6166' }, { tag: t.number, color: '#5c6166' }, { tag: t.bool, color: '#5c6166' }, { tag: t.null, color: '#5c6166' }, { tag: t.keyword, color: '#5c6166' }, { tag: t.operator, color: '#5c6166' }, { tag: t.className, color: '#5c6166' }, { tag: t.definition(t.typeName), color: '#5c6166' }, { tag: t.typeName, color: '#5c6166' }, { tag: t.angleBracket, color: '#5c6166' }, { tag: t.tagName, color: '#5c6166' }, { tag: t.attributeName, color: '#5c6166' }, ], }); function App() { return ( <CodeMirror value="console.log('hello world!');" height="200px" theme={myTheme} extensions={[javascript({ jsx: true })]} onChange={(value, viewUpdate) => { console.log('value:', value); }} /> ); } export default App; ``` ## Themes **abcdef** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/abcdef"> <img width="436" alt="codemirror-theme-abcdef" src="https://user-images.githubusercontent.com/1680273/176573508-705562ad-16ec-4b16-994e-f235a9331a3f.png"> </a> **android studio** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/xcode/light"> <img width="436" alt="codemirror-theme-androidstudio" src="https://user-images.githubusercontent.com/1680273/177484354-0a4fa43e-de96-409f-83e2-61808f2347e6.png"> </a> **atom one** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/xcode/light"> <img width="436" alt="codemirror-theme-androidstudio" src="https://user-images.githubusercontent.com/1680273/181795374-7a25cb90-5d77-4f86-9cbc-b1e12dc939d3.png"> </a> **aura** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/aura"> <img width="436" alt="codemirror-theme-aura" src="https://user-images.githubusercontent.com/1680273/206092773-8140fc6b-119f-4271-a821-7dc6bcbc1c63.png"> </a> **bbedit** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/bbedit"> <img width="436" alt="codemirror-theme-bbedit" src="https://user-images.githubusercontent.com/1680273/183550552-df398e5b-fab2-4ce5-bdd0-5e3612e3e5d9.png"> </a> **bespin** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/bespin"> <img width="436" alt="codemirror-theme-bespin" src="https://user-images.githubusercontent.com/1680273/176573408-0fd54981-471a-4ef8-91d4-8ad4b159c1e0.png"> </a> **darcula** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/darcula"> <img width="436" alt="codemirror-theme-darcula" src="https://user-images.githubusercontent.com/1680273/176573321-3015b1b4-3455-497f-ad16-dd2090d7848d.png"> </a> **dracula** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/dracula"> <img width="436" alt="codemirror-theme-dracula" src="https://user-images.githubusercontent.com/1680273/176573236-43928ba2-0eb1-4b59-9495-d39b6e3df81c.png"> </a> **duotone** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/duotone/dark"> <img width="436" alt="codemirror-theme-duotone dark" src="https://user-images.githubusercontent.com/1680273/176572959-adfc1284-4c70-48df-8aeb-9a47ff76b2f2.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/duotone/light"> <img width="436" alt="codemirror-theme-duotone light" src="https://user-images.githubusercontent.com/1680273/176573139-5c22ed62-6000-40da-b080-59c83e6181e2.png"> </a> **eclipse** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/eclipse"> <img width="436" alt="codemirror-theme-eclipse" src="https://user-images.githubusercontent.com/1680273/176572785-4f56f11a-018b-4f86-9088-e6f71f745cfb.png"> </a> **github** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/github/dark"> <img width="436" alt="codemirror-theme-github dark" src="https://user-images.githubusercontent.com/1680273/177048035-644af599-aaf1-41d8-86ea-9ea8c3a1a0c5.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/github/light"> <img width="436" alt="codemirror-theme-github light" src="https://user-images.githubusercontent.com/1680273/177048005-32794f23-8bff-4059-babf-21316d886e65.png"> </a> **gruvbox** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/gruvbox/dark"> <img width="436" alt="codemirror-theme-gruvbox-dark" src="https://user-images.githubusercontent.com/1680273/206087857-d0a85219-34ad-4e79-9cdf-183f67e1085d.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/gruvbox/light"> <img width="436" alt="codemirror-theme-eclipse" src="https://user-images.githubusercontent.com/1680273/206087911-49db6624-ab8c-434e-9b8a-84132fe206f9.png"> </a> **material** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/material/dark"> <img width="436" alt="codemirror-theme-material" src="https://user-images.githubusercontent.com/1680273/205537793-79f9c99c-831a-4ce3-8189-78b42896656f.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/material/light"> <img width="436" alt="codemirror-theme-material" src="https://user-images.githubusercontent.com/1680273/206124615-b3896e2c-d299-4609-b1d9-523ea1cf9f5b.png"> </a> **noctis-lilac** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/noctis-lilac"> <img width="436" alt="codemirror-theme-noctis-lilac" src="https://user-images.githubusercontent.com/1680273/206088068-55e9a25b-eb77-4e1a-91bb-f39cbba84981.png"> </a> **nord** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/nord"> <img width="436" alt="codemirror-theme-nord" src="https://user-images.githubusercontent.com/1680273/205498304-956bc719-1472-40f0-9c3f-21ac5b9f97a6.png"> </a> **okaidia** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/okaidia"> <img width="436" alt="codemirror-theme-okaidia" src="https://user-images.githubusercontent.com/1680273/176572694-b9aface9-9646-4e0e-a211-a8aa92dabc31.png"> </a> **solarized** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/solarized/light"> <img width="436" alt="codemirror-theme-solarized" src="https://user-images.githubusercontent.com/1680273/205544435-a080d1d4-6da9-4f1d-aa10-5f2207d31176.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/solarized/dark"> <img width="436" alt="codemirror-theme-solarized" src="https://user-images.githubusercontent.com/1680273/205547403-96db62c3-d061-4dee-88d0-c86ed17e7489.png"> </a> **sublime** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/sublime"> <img width="436" alt="codemirror-theme-sublime" src="https://user-images.githubusercontent.com/1680273/176572314-cc296f81-0763-485c-8fa2-7d61b24ad09b.png"> </a> **tokyo-night** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night"> <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"> <img width="436" alt="codemirror-theme-vscode dark" src="https://user-images.githubusercontent.com/1680273/202690670-385808e2-6346-4e36-a3d6-6d9fc1f216dc.png"> </a> **xcode** <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/xcode/dark"> <img width="436" alt="codemirror-theme-xcode dark" src="https://user-images.githubusercontent.com/1680273/206087681-537b9c1f-0dce-42a4-854d-036147935e82.png"> </a> <a href="https://uiwjs.github.io/react-codemirror/#/theme/data/xcode/light"> <img width="436" alt="codemirror-theme-xcode light" src="https://user-images.githubusercontent.com/1680273/206087526-9613a546-f129-4e01-9263-5a75f3f039a7.png"> </a> ## Props ```ts import { Extension } from '@codemirror/state'; import { TagStyle } from '@codemirror/language'; export interface CreateThemeOptions { /** * Theme inheritance. Determines which styles CodeMirror will apply by default. */ theme: Theme; /** * Settings to customize the look of the editor, like background, gutter, selection and others. */ settings: Settings; /** Syntax highlighting styles. */ styles: TagStyle[]; } type Theme = 'light' | 'dark'; export interface Settings { /** Editor background color. */ background?: string; /** Editor background image. */ backgroundImage?: string; /** Default text color. */ foreground?: string; /** Caret color. */ caret?: string; /** Selection background. */ selection?: string; /** Selection match background. */ selectionMatch?: string; /** Background of highlighted lines. */ lineHighlight?: string; /** Gutter background. */ gutterBackground?: string; /** Text color inside gutter. */ gutterForeground?: string; /** Text active color inside gutter. */ gutterActiveForeground?: string; /** Gutter right border color. */ gutterBorder?: string; /** set editor font */ fontFamily?: string; } export declare const createTheme: ({ theme, settings, styles }: CreateThemeOptions) => Extension; export default createTheme; ``` ### Related - [@uiw/react-textarea-code-editor](https://github.com/uiwjs/react-textarea-code-editor): A simple code editor with syntax highlighting. - [@uiw/react-md-editor](https://github.com/uiwjs/react-md-editor): A simple markdown editor with preview, implemented with React.js and TypeScript. - [@uiw/react-monacoeditor](https://github.com/jaywcjlove/react-monacoeditor): Monaco Editor component for React. - [@uiw/react-markdown-editor](https://github.com/uiwjs/react-markdown-editor): A markdown editor with preview, implemented with React.js and TypeScript. - [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview): React component preview markdown text in web browser. - [Online JSON Viewer](https://github.com/uiwjs/json-viewer) Online JSON Viewer, JSON Beautifier to beautify and tree view of JSON data - It works as JSON Pretty Print to pretty print JSON data. ## 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.