Browse Source

refactor(nc-gui): use color picker in share view

pull/3669/head
braks 2 years ago committed by Raju Udava
parent
commit
0128f2be0e
  1. 35
      packages/nc-gui/components/smartsheet/toolbar/ShareView.vue
  2. 1
      packages/nc-gui/lib/types.ts
  3. 6
      packages/nc-gui/pages/[projectType]/form/[viewId]/index.vue

35
packages/nc-gui/components/smartsheet/toolbar/ShareView.vue

@ -1,10 +1,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ViewTypes } from 'nocodb-sdk' import { ViewTypes } from 'nocodb-sdk'
import { isString } from '@vueuse/core' import { isString } from '@vueuse/core'
import tinycolor from 'tinycolor2'
import { import {
computed, computed,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
message, message,
projectThemeColors,
ref, ref,
useCopy, useCopy,
useDashboard, useDashboard,
@ -12,14 +14,11 @@ import {
useNuxtApp, useNuxtApp,
useProject, useProject,
useSmartsheetStoreOrThrow, useSmartsheetStoreOrThrow,
useTheme,
useUIPermission, useUIPermission,
watch, watch,
} from '#imports' } from '#imports'
import type { SharedView } from '~/lib' import type { SharedView } from '~/lib'
const { theme } = useTheme()
const { t } = useI18n() const { t } = useI18n()
const { view, $api } = useSmartsheetStoreOrThrow() const { view, $api } = useSmartsheetStoreOrThrow()
@ -57,11 +56,11 @@ const surveyMode = computed({
}) })
const viewTheme = computed({ const viewTheme = computed({
get: () => !!shared.value.meta.theme, get: () => !!shared.value.meta.withTheme,
set: (hasTheme) => { set: (withTheme) => {
shared.value.meta = { shared.value.meta = {
...shared.value.meta, ...shared.value.meta,
theme: hasTheme ? { ...theme.value } : undefined, withTheme,
} }
saveTheme() saveTheme()
}, },
@ -143,6 +142,20 @@ const saveShareLinkPassword = async () => {
$e('a:view:share:enable-pwd') $e('a:view:share:enable-pwd')
} }
function onChangeTheme(color: string) {
const tcolor = tinycolor(color)
if (tcolor.isValid()) {
const complement = tcolor.complement()
shared.value.meta.theme = {
primaryColor: color,
accentColor: complement.toHex8String(),
}
saveTheme()
}
}
const copyLink = async () => { const copyLink = async () => {
if (sharedViewUrl.value) { if (sharedViewUrl.value) {
await copy(sharedViewUrl.value) await copy(sharedViewUrl.value)
@ -210,6 +223,16 @@ watch(passwordProtected, (value) => {
<div> <div>
<!-- todo: i18n --> <!-- todo: i18n -->
<a-checkbox v-model:checked="viewTheme" class="!text-xs"> Use Theme </a-checkbox> <a-checkbox v-model:checked="viewTheme" class="!text-xs"> Use Theme </a-checkbox>
<div v-if="viewTheme" class="flex pl-2">
<LazyGeneralColorPicker
:model-value="shared.meta.theme?.primaryColor"
:colors="projectThemeColors"
:row-size="9"
:advanced="false"
@input="onChangeTheme"
/>
</div>
</div> </div>
<div> <div>

1
packages/nc-gui/lib/types.ts

@ -73,6 +73,7 @@ export interface TabItem {
export interface SharedViewMeta extends Record<string, any> { export interface SharedViewMeta extends Record<string, any> {
surveyMode?: boolean surveyMode?: boolean
withTheme?: boolean
theme?: Partial<ThemeConfig> theme?: Partial<ThemeConfig>
allowCSVDownload?: boolean allowCSVDownload?: boolean
} }

6
packages/nc-gui/pages/[projectType]/form/[viewId]/index.vue

@ -12,9 +12,9 @@ const route = useRoute()
const router = useRouter() const router = useRouter()
watch( watch(
() => sharedViewMeta.value.theme, () => sharedViewMeta.value.withTheme,
(nextTheme) => { (hasTheme) => {
if (nextTheme) setTheme(nextTheme) if (hasTheme && sharedViewMeta.value.theme) setTheme(sharedViewMeta.value.theme)
}, },
{ immediate: true }, { immediate: true },
) )

Loading…
Cancel
Save