Skip to content

Commit c93fa68

Browse files
committed
fix: add props compact and copy
1 parent 1205b9d commit c93fa68

2 files changed

Lines changed: 87 additions & 15 deletions

File tree

adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,30 @@ For fields containing sensitive data (like passwords, API keys, tokens, or other
605605
606606
The renderer wraps the standard value output and adds a click-to-reveal blur effect. Clicking again hides the value.
607607
608+
For long values (like API keys) you can enable compact mode by passing `compact: true` via `meta`. When set, the value is shortened the same way as the `CompactUUID` renderer (first 4 + `...` + last 4 characters). In compact mode you can additionally pass `copy: true` to render a copy-to-clipboard button next to the value:
609+
610+
```ts title='./resources/anyResource.ts'
611+
columns: [
612+
...
613+
{
614+
name: 'api_key',
615+
components: {
616+
show: {
617+
//diff-add
618+
file: '@/renderers/SensitiveBlurCell.vue',
619+
//diff-add
620+
meta: { compact: true, copy: true },
621+
},
622+
list: {
623+
//diff-add
624+
file: '@/renderers/SensitiveBlurCell.vue',
625+
//diff-add
626+
meta: { compact: true, copy: true },
627+
},
628+
},
629+
...
630+
```
631+
608632
609633
### Custom filter component for square meters
610634
Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,87 @@
11
<template>
22
<div class="inline-flex items-center gap-1">
3-
<div
4-
class="overflow-hidden max-h-[20px] rounded-default"
5-
:title="show ? $t('Click to hide') : $t('Click to show')"
6-
@click="toggle"
7-
>
8-
<span
9-
class="cursor-pointer select-none transition-all duration-200 text-lightListTableText dark:text-darkListTableText"
10-
:class="{
11-
'blur-[7px] hover:blur-[5px] brightness-50 dark:brightness-150': !show,
12-
}"
3+
<Tooltip>
4+
<div
5+
class="overflow-hidden max-h-[20px] rounded-default"
6+
:class="{ 'shrink-0 w-[90px]': compact }"
7+
@click="toggle"
138
>
14-
<ValueRenderer :column="column" :record="record" />
15-
</span>
16-
</div>
9+
<span
10+
class="cursor-pointer select-none transition-all duration-200 text-lightListTableText dark:text-darkListTableText"
11+
:class="{
12+
'block truncate': compact,
13+
'blur-[7px] hover:blur-[5px] brightness-50 dark:brightness-150': !show,
14+
}"
15+
>
16+
<template v-if="compact">{{ visualValue }}</template>
17+
<ValueRenderer v-else :column="column" :record="record" />
18+
</span>
19+
</div>
20+
<template #tooltip>
21+
<span class="whitespace-nowrap">{{ tooltipText }}</span>
22+
</template>
23+
</Tooltip>
24+
25+
<IconFileCopyAltSolid
26+
v-if="showCopy && rawValue"
27+
@click.stop="copyToCB"
28+
class="shrink-0 min-w-5 min-h-5 cursor-pointer text-lightPrimary dark:text-darkPrimary"
29+
/>
1730
</div>
1831
</template>
1932

2033
<script setup lang="ts">
21-
import { ref } from 'vue';
34+
import { ref, computed } from 'vue';
35+
import { useI18n } from 'vue-i18n';
36+
import { IconFileCopyAltSolid } from '@iconify-prerendered/vue-flowbite';
2237
import ValueRenderer from '@/components/ValueRenderer.vue';
38+
import Tooltip from '@/afcl/Tooltip.vue';
39+
import { useAdminforth } from '@/adminforth';
2340
import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common';
2441
2542
const props = defineProps<{
2643
column: AdminForthResourceColumnCommon;
2744
record: any;
28-
meta: any;
45+
meta: { compact?: boolean; copy?: boolean } | any;
2946
resource: AdminForthResourceCommon;
3047
adminUser: AdminUser;
3148
}>();
3249
50+
const { t } = useI18n();
51+
const { alert } = useAdminforth();
52+
3353
const show = ref(false);
3454
55+
const rawValue = computed(() => props.record[props.column.name]);
56+
57+
const compact = computed(() => props.meta?.compact);
58+
const showCopy = computed(() => compact.value && props.meta?.copy);
59+
const visualValue = computed(() => {
60+
const val = rawValue.value;
61+
if (val && String(val).length > 8) {
62+
const s = String(val);
63+
return `${s.slice(0, 4)}...${s.slice(-4)}`;
64+
}
65+
return val;
66+
});
67+
68+
const tooltipText = computed(() => {
69+
if (compact.value && show.value) {
70+
return rawValue.value;
71+
}
72+
return show.value ? t('Click to hide') : t('Click to show');
73+
});
74+
3575
function toggle(event: MouseEvent) {
3676
show.value = !show.value;
3777
event.stopPropagation();
3878
}
79+
80+
function copyToCB() {
81+
navigator.clipboard.writeText(rawValue.value);
82+
alert({
83+
message: t('Copied to clipboard'),
84+
variant: 'success',
85+
});
86+
}
3987
</script>

0 commit comments

Comments
 (0)