generated from sonofmagic/npm-lib-template
-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c24bfea
commit 9159056
Showing
9 changed files
with
142 additions
and
22 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# theme-transition | ||
|
||
## Usage | ||
|
||
```bash | ||
pnpm add theme-transition | ||
``` | ||
|
||
## Import Js | ||
|
||
```js | ||
import { useToggleDark } from 'theme-transition' | ||
|
||
const { toggleDark } = useToggleDark({ | ||
getDarkValue: () => { | ||
return isDark.value | ||
}, | ||
toggle: () => { | ||
isDark.value = !isDark.value | ||
}, | ||
// viewTransition: { | ||
// after: () => { | ||
// return nextTick() | ||
// }, | ||
// }, | ||
}) | ||
|
||
toggleDark(MouseEvent) | ||
``` | ||
|
||
## Import Style | ||
|
||
### Scss | ||
|
||
```scss | ||
@use 'theme-transition/scss/mixins.scss' as M; | ||
// pass your theme css selector | ||
@include M.theme-transition('[data-theme="dark"]'); | ||
``` | ||
|
||
### Tailwindcss Plugin | ||
|
||
```ts | ||
import type { Config } from 'tailwindcss' | ||
import { themeTransitionPlugin } from 'theme-transition/tailwindcss' | ||
|
||
export default <Config> { | ||
plugins: [themeTransitionPlugin()], | ||
} | ||
``` | ||
|
||
### Css | ||
|
||
```css | ||
@import 'theme-transition/css'; | ||
``` | ||
|
||
```js | ||
import 'theme-transition/css' | ||
``` | ||
|
||
> css only `.dark` selector, so use scss or tailwindcss plugin |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "theme-transition", | ||
"type": "module", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "theme-transition css,scss and tailwindcss plugin", | ||
"author": "ice breaker <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -20,7 +20,7 @@ | |
"sideEffects": false, | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./tailwindcss": "./src/tailwindcss", | ||
"./tailwindcss": "./src/tailwindcss.ts", | ||
"./scss": "./scss/index.scss", | ||
"./scss/mixins": "./scss/mixins.scss", | ||
"./scss/*": "./scss/*", | ||
|
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
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
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,47 @@ | ||
import type { Props } from '@theme/ColorModeToggle' | ||
import OriginalToggle from '@theme-original/ColorModeToggle' | ||
import { useToggleDark } from 'theme-transition' | ||
|
||
function Toggler(props: Props) { | ||
const { toggleDark } = useToggleDark({ | ||
getDarkValue() { | ||
return props.value === 'dark' | ||
}, | ||
toggle() { | ||
if (props.value === 'dark') { | ||
props.onChange('light') | ||
} | ||
else { | ||
props.onChange('dark') | ||
} | ||
}, | ||
viewTransition: { | ||
after() { | ||
return new Promise((r) => { | ||
setTimeout(() => { | ||
r(undefined) | ||
}, 0) | ||
}) | ||
}, | ||
}, | ||
duration: 4000, | ||
}) | ||
return ( | ||
<div onClick={(e) => { | ||
toggleDark(e as unknown as MouseEvent) | ||
}} | ||
> | ||
<OriginalToggle | ||
{...props} | ||
onChange={() => { | ||
// props.onChange(colorMode) | ||
// toggleDark() | ||
}} | ||
> | ||
</OriginalToggle> | ||
</div> | ||
|
||
) | ||
} | ||
|
||
export default Toggler |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import type { Config } from 'tailwindcss' | ||
import { themeTransitionPlugin } from 'theme-transition/tailwindcss' | ||
|
||
export default <Config> { | ||
content: ['./src/**/*.{js,jsx,ts,tsx}', './docusaurus.config.ts', 'docs/**/*.{md,mdx}'], | ||
darkMode: ['selector', '[data-theme="dark"]'], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [themeTransitionPlugin()], | ||
corePlugins: { | ||
preflight: false, | ||
}, | ||
} |