feat: Add theme prop (#3228)

* support appearance when updating scene data

* works!

* whoops, missed a prop

* hide appearance button when prop is not set

* cleanup

* fix export + rename prop to theme

* rename to showThemeBtn, hide via react instead of css

* adapt to new state name

* add tests and css selector to target the dark mode toggle

* updated changelog and readme

* fix markdown rendering in readme

* pr feedback
This commit is contained in:
Jeremy Press 2021-03-15 11:33:46 -07:00 committed by GitHub
parent 1f295955d0
commit 84a1863233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 10 deletions

View file

@ -18,6 +18,7 @@ Please add the latest change on the top under the correct section.
### Features
- Add a `theme` prop to indicate Excalidraw's theme. [#3228](https://github.com/excalidraw/excalidraw/pull/3228). When this prop is passed, the theme is fully controlled by host app.
- Support `libraryReturnUrl` prop to indicate what URL to install libraries to [#3227](https://github.com/excalidraw/excalidraw/pull/3227).
### Refactor

View file

@ -377,6 +377,7 @@ export default function IndexPage() {
| [`zenModeEnabled`](#zenModeEnabled) | boolean | | This implies if the zen mode is enabled |
| [`gridModeEnabled`](#gridModeEnabled) | boolean | | This implies if the grid mode is enabled |
| [`libraryReturnUrl`](#libraryReturnUrl) | string | | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to |
| [`theme`](#theme) | `light` or `dark` | | The theme of the Excalidraw component |
#### `width`
@ -538,6 +539,10 @@ This prop indicates whether the shows the grid. When supplied, the value takes p
If supplied, this URL will be used when user tries to install a library from [libraries.excalidraw.com](https://libraries.excalidraw.com). Default to `window.location.origin`.
### `theme`
This prop controls Excalidraw's theme. When supplied, the value takes precedence over `intialData.appState.theme`, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app.
### Extra API's
#### `getSceneVersion`

View file

@ -30,6 +30,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
zenModeEnabled,
gridModeEnabled,
libraryReturnUrl,
theme,
} = props;
useEffect(() => {
@ -71,6 +72,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
zenModeEnabled={zenModeEnabled}
gridModeEnabled={gridModeEnabled}
libraryReturnUrl={libraryReturnUrl}
theme={theme}
/>
</IsMobileProvider>
</InitializeApp>