Skip to content

Commit 6c46385

Browse files
committed
feat: add the darkmode support
1 parent 24567ac commit 6c46385

File tree

10 files changed

+125
-109
lines changed

10 files changed

+125
-109
lines changed

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ declare module '@vue/runtime-core' {
1616
'Logos:nuxtIcon': typeof import('~icons/logos/nuxt-icon')['default']
1717
'Logos:vue': typeof import('~icons/logos/vue')['default']
1818
'Mdi:heart': typeof import('~icons/mdi/heart')['default']
19+
'Ri:moonLine': typeof import('~icons/ri/moon-line')['default']
20+
'Ri:sunLine': typeof import('~icons/ri/sun-line')['default']
1921
ToggleButton: typeof import('./src/components/ToggleButton.vue')['default']
2022
}
2123
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@
4444
"@stitches/core": "^1.2.8",
4545
"@supabase/auth-ui-shared": "^0.1.6",
4646
"@supabase/supabase-js": "^2.31.0",
47+
"@types/lodash.clonedeep": "^4.5.7",
4748
"@types/node": "^18.7.14",
4849
"@unocss/reset": "^0.45.18",
4950
"@vitejs/plugin-vue": "^4.2.3",
5051
"@vueuse/core": "^9.1.1",
5152
"@vueuse/head": "^1.1.23",
5253
"highlight.js": "^11.6.0",
54+
"lodash.clonedeep": "^4.5.0",
5355
"typescript": "^4.6.4",
5456
"unocss": "^0.55.0",
5557
"unplugin-icons": "^0.14.9",

packages/Auth.vue

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,11 @@
6666

6767
<script lang="ts" setup>
6868
import { provide, ref, watch, computed } from 'vue'
69-
import { Provider, SupabaseClient } from '@supabase/supabase-js'
70-
import {
71-
I18nVariables,
72-
OtpType,
73-
ProviderScopes,
74-
RedirectTo,
75-
SocialLayout,
76-
ViewType,
77-
en,
78-
merge
79-
} from '@supabase/auth-ui-shared'
69+
import { I18nVariables, ViewType, en, merge } from '@supabase/auth-ui-shared'
8070
import { createStitches } from '@stitches/core'
71+
import cloneDeep from 'lodash.clonedeep'
8172
82-
import { Appearance, AuthViewKey } from './types'
73+
import { AuthProps, AuthViewKey } from './types'
8374
import SocialAuthContainer from './auth/SocialAuthContainer.vue'
8475
import EmailAuth from './auth/EmailAuth.vue'
8576
import SocialAuth from './auth/SocialAuth.vue'
@@ -88,37 +79,6 @@ import ForgottenPassword from './auth/ForgottenPassword.vue'
8879
import UpdatePassword from './auth/UpdatePassword.vue'
8980
import VerifyOtp from './auth/VerifyOtp.vue'
9081
91-
interface AuthProps {
92-
supabaseClient: SupabaseClient
93-
socialLayout?: SocialLayout
94-
providers?: Provider[]
95-
providerScopes?: Partial<ProviderScopes>
96-
queryParams?: {
97-
[key: string]: string
98-
}
99-
view?: ViewType
100-
redirectTo?: RedirectTo
101-
appearance?: Appearance
102-
onlyThirdPartyProviders?: boolean
103-
magicLink?: boolean
104-
showLinks?: boolean
105-
otpType?: OtpType
106-
additionalData?: {
107-
[key: string]: any
108-
}
109-
/**
110-
* This will toggle on the dark variation of the theme
111-
*/
112-
dark?: boolean
113-
/**
114-
* Override the labels and button text
115-
*/
116-
localization?: {
117-
variables?: I18nVariables
118-
}
119-
theme?: 'default' | string
120-
}
121-
12282
const props = withDefaults(defineProps<AuthProps>(), {
12383
view: 'sign_in',
12484
socialLayout: 'vertical',
@@ -156,16 +116,18 @@ const isSignView = computed(() => {
156116
})
157117
158118
const theme = computed(() => {
119+
const appearanceTheme = cloneDeep(props.appearance?.theme)
120+
const appearanceVariables = cloneDeep(props.appearance?.variables)
159121
return merge(
160-
props?.appearance?.theme?.default ?? {},
161-
props?.appearance?.theme?.[props.theme] ?? {},
162-
props?.appearance?.variables?.default ?? {},
163-
props?.appearance?.variables?.[props?.theme] ?? {}
122+
appearanceTheme?.default ?? {},
123+
appearanceTheme?.[props.theme] ?? {},
124+
appearanceVariables?.default ?? {},
125+
appearanceVariables?.[props?.theme] ?? {}
164126
)
165127
})
166128
createStitches({ theme: theme.value })
167129
watch(
168-
() => props.appearance,
130+
() => [props.appearance, props.theme],
169131
() => {
170132
createStitches({ theme: theme.value })
171133
},

packages/types.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { CSSProperties, InjectionKey, Ref } from 'vue'
2-
import {
3-
AuthProviders,
1+
import type { CSSProperties, InjectionKey, Ref } from 'vue'
2+
import type {
43
BaseAppearance,
5-
BaseAuth,
64
I18nVariables,
5+
OtpType,
6+
ProviderScopes,
7+
RedirectTo,
78
SocialLayout,
89
ViewType
910
} from '@supabase/auth-ui-shared'
10-
import { SupabaseClient } from '@supabase/supabase-js'
11-
import type { Session, User } from '@supabase/supabase-js'
11+
import type {
12+
Provider,
13+
Session,
14+
SupabaseClient,
15+
User
16+
} from '@supabase/supabase-js'
1217

1318
export interface Appearance extends BaseAppearance {
1419
style?: {
@@ -23,19 +28,23 @@ export interface Appearance extends BaseAppearance {
2328
}
2429
}
2530

26-
export interface Auth extends BaseAuth {
27-
appearance?: BaseAppearance
28-
}
29-
30-
export interface AuthProps {
31-
supabaseClient: SupabaseClient // Supabase Client
32-
socialLayout?: SocialLayout // This determines how the social providers show be displayed
33-
providers?: AuthProviders // This is a list of social providers to be used
34-
view?: ViewType // This determines the type of auth component to be shown
35-
redirectTo?: undefined | string // This will determine where to redirect the user to after some auth operations
36-
onlyThirdPartyProviders?: boolean // This will toggle if to show just the social providers without the EmailAuth component
37-
magicLink?: boolean // This will toggle the 'Send magic link' on the links
38-
showLinks?: boolean // This will toggle the links on the auth component to change the auth view
31+
interface BaseAuth {
32+
supabaseClient: SupabaseClient
33+
socialLayout?: SocialLayout
34+
providers?: Provider[]
35+
providerScopes?: Partial<ProviderScopes>
36+
queryParams?: {
37+
[key: string]: string
38+
}
39+
view?: ViewType
40+
redirectTo?: RedirectTo
41+
onlyThirdPartyProviders?: boolean
42+
magicLink?: boolean
43+
showLinks?: boolean
44+
otpType?: OtpType
45+
additionalData?: {
46+
[key: string]: any
47+
}
3948
/**
4049
* This will toggle on the dark variation of the theme
4150
*/
@@ -44,13 +53,15 @@ export interface AuthProps {
4453
* Override the labels and button text
4554
*/
4655
localization?: {
47-
lang?: 'en' | 'zh'
4856
variables?: I18nVariables
4957
}
50-
appearance?: BaseAppearance
5158
theme?: 'default' | string
5259
}
5360

61+
export interface AuthProps extends BaseAuth {
62+
appearance?: BaseAppearance
63+
}
64+
5465
export type AuthProvider =
5566
| 'google'
5667
| 'facebook'

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)