@globalbrain/sefirot 2.5.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,21 @@ import { computed } from 'vue'
3
3
  import SIcon from './SIcon.vue'
4
4
  import SLink from './SLink.vue'
5
5
 
6
+ export type Color =
7
+ | 'neutral'
8
+ | 'soft'
9
+ | 'mute'
10
+ | 'info'
11
+ | 'warning'
12
+ | 'danger'
13
+
6
14
  const props = defineProps<{
7
15
  value?: any
8
16
  record: any
9
17
  icon?: any
10
18
  getter?: string | ((value: any) => string)
11
- color?: 'neutral' | 'soft' | 'mute'
12
- iconColor?: 'neutral' | 'soft' | 'mute'
19
+ color?: Color | ((value: any, record: any) => Color)
20
+ iconColor?: Color | ((value: any, record: any) => Color)
13
21
  link?(value: any, record: any): string
14
22
  }>()
15
23
 
@@ -22,15 +30,27 @@ const _value = computed(() => {
22
30
  ? props.getter
23
31
  : props.getter(props.value)
24
32
  })
33
+
34
+ const _color = computed(() => {
35
+ return typeof props.color === 'function'
36
+ ? props.color(props.value, props.record)
37
+ : props.color ?? 'neutral'
38
+ })
39
+
40
+ const _iconColor = computed(() => {
41
+ return typeof props.iconColor === 'function'
42
+ ? props.iconColor(props.value, props.record)
43
+ : props.iconColor ?? 'neutral'
44
+ })
25
45
  </script>
26
46
 
27
47
  <template>
28
- <div class="STableCellText" :class="[{ link }, color ?? 'neutral']">
48
+ <div class="STableCellText" :class="[{ link }, _color]">
29
49
  <SLink v-if="_value" class="container" :href="link?.(value, record)">
30
- <div v-if="icon" class="icon" :class="[iconColor ?? color ?? 'neutral']">
50
+ <div v-if="icon" class="icon" :class="[_iconColor ?? _color]">
31
51
  <SIcon :icon="icon" class="svg" />
32
52
  </div>
33
- <div class="text" :class="[color ?? 'neutral']">
53
+ <div class="text" :class="[_color]">
34
54
  {{ _value }}
35
55
  </div>
36
56
  </SLink>
@@ -39,13 +59,13 @@ const _value = computed(() => {
39
59
 
40
60
  <style scoped lang="postcss">
41
61
  .STableCellText {
42
- padding: 8px 16px;
43
62
  min-height: 40px;
44
63
  }
45
64
 
46
65
  .container {
47
66
  display: flex;
48
67
  gap: 4px;
68
+ padding: 8px 16px;
49
69
  }
50
70
 
51
71
  .text {
@@ -60,6 +80,9 @@ const _value = computed(() => {
60
80
  &.neutral { color: var(--c-text-1); }
61
81
  &.soft { color: var(--c-text-2); }
62
82
  &.mute { color: var(--c-text-3); }
83
+ &.info { color: var(--c-info); }
84
+ &.warning { color: var(--c-warning); }
85
+ &.danger { color: var(--c-danger); }
63
86
 
64
87
  .STableCellText.link & { color: var(--c-info); }
65
88
  .STableCellText.link:hover & { color: var(--c-info-dark); }
@@ -70,6 +93,12 @@ const _value = computed(() => {
70
93
  .STableCellText.link:hover &.soft { color: var(--c-info); }
71
94
  .STableCellText.link &.mute { color: var(--c-text-3); }
72
95
  .STableCellText.link:hover &.mute { color: var(--c-info); }
96
+ .STableCellText.link &.info { color: var(--c-info); }
97
+ .STableCellText.link:hover &.info { color: var(--c-info-dark); }
98
+ .STableCellText.link &.warning { color: var(--c-warning); }
99
+ .STableCellText.link:hover &.warning { color: var(--c-warning-darker); }
100
+ .STableCellText.link &.danger { color: var(--c-danger); }
101
+ .STableCellText.link:hover &.danger { color: var(--c-danger-dark); }
73
102
  }
74
103
 
75
104
  .icon {
@@ -95,6 +124,12 @@ const _value = computed(() => {
95
124
  .STableCellText.link:hover &.soft { color: var(--c-info); }
96
125
  .STableCellText.link &.mute { color: var(--c-text-3); }
97
126
  .STableCellText.link:hover &.mute { color: var(--c-info); }
127
+ .STableCellText.link &.info { color: var(--c-info); }
128
+ .STableCellText.link:hover &.info { color: var(--c-info-dark); }
129
+ .STableCellText.link &.warning { color: var(--c-warning); }
130
+ .STableCellText.link:hover &.warning { color: var(--c-warning-dark); }
131
+ .STableCellText.link &.danger { color: var(--c-danger); }
132
+ .STableCellText.link:hover &.danger { color: var(--c-danger-dark); }
98
133
  }
99
134
 
100
135
  .svg {
@@ -6,9 +6,9 @@ import { format } from '../support/Num'
6
6
  import SIcon from './SIcon.vue'
7
7
 
8
8
  const props = defineProps<{
9
- total?: number
10
- page?: number
11
- perPage?: number
9
+ total?: number | null
10
+ page?: number | null
11
+ perPage?: number | null
12
12
  borderless?: boolean
13
13
  onPrev?(): void
14
14
  onNext?(): void
@@ -2,7 +2,7 @@
2
2
  import { format } from '../support/Num'
3
3
 
4
4
  defineProps<{
5
- total?: number
5
+ total?: number | null
6
6
  reset?: boolean
7
7
  borderless?: boolean
8
8
  onReset?(): void
@@ -1,7 +1,7 @@
1
1
  import { watchOnce } from '@vueuse/core'
2
2
  import cloneDeep from 'lodash-es/cloneDeep'
3
3
  import { WatchSource, reactive } from 'vue'
4
- import { isObject } from '../support/Utils'
4
+ import { isNullish, isObject } from '../support/Utils'
5
5
 
6
6
  export interface Data<T extends Record<string, any>> {
7
7
  state: T
@@ -25,7 +25,7 @@ export interface UseDataInputUtils {
25
25
  def<T>(
26
26
  value: any,
27
27
  source: WatchSource<T>,
28
- cb: (value: Exclude<T, undefined>) => void
28
+ cb: (value: Exclude<T, null | undefined>) => void
29
29
  ): Def<T>
30
30
  }
31
31
 
@@ -81,11 +81,14 @@ function createState<T extends Record<string, any>>(
81
81
  }
82
82
 
83
83
  function handleDefs<T extends Record<string, any>>(
84
- defs: [string, Def][], state: T
84
+ defs: [string, Def][],
85
+ state: T
85
86
  ): void {
86
87
  defs.forEach(([key, def]) => {
87
88
  watchOnce(def.source, (value: any) => {
88
- (state as any)[key] = def.cb(value)
89
+ if (!isNullish(value)) {
90
+ (state as any)[key] = def.cb(value)
91
+ }
89
92
  })
90
93
  })
91
94
  }
@@ -93,7 +96,7 @@ function handleDefs<T extends Record<string, any>>(
93
96
  function def<T>(
94
97
  value: any,
95
98
  source: WatchSource<T>,
96
- cb: (value: Exclude<T, undefined>) => void
99
+ cb: (value: Exclude<T, null | undefined>) => void
97
100
  ): Def {
98
101
  return {
99
102
  __isDef: true,
@@ -5,10 +5,10 @@ import { DropdownSection } from './Dropdown'
5
5
  export interface Table {
6
6
  orders: string[]
7
7
  columns: TableColumns
8
- records?: Record<string, any>[]
9
- total?: number
10
- page?: number
11
- perPage?: number
8
+ records?: Record<string, any>[] | null
9
+ total?: number | null
10
+ page?: number | null
11
+ perPage?: number | null
12
12
  reset?: boolean
13
13
  borderless?: boolean
14
14
  loading?: boolean
@@ -47,10 +47,18 @@ export interface TableCellText extends TableCellBase {
47
47
  icon?: any
48
48
  value?: string | ((value: any) => string)
49
49
  link?(value: any, record: any): string
50
- color?: 'neutral' | 'soft' | 'mute'
51
- iconColor?: 'neutral' | 'soft' | 'mute'
50
+ color?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor)
51
+ iconColor?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor)
52
52
  }
53
53
 
54
+ export type TableCellTextColor =
55
+ | 'neutral'
56
+ | 'soft'
57
+ | 'mute'
58
+ | 'info'
59
+ | 'warning'
60
+ | 'danger'
61
+
54
62
  export interface TableCellDay extends TableCellBase {
55
63
  type: 'day'
56
64
  format?: string
@@ -93,10 +101,10 @@ export interface TableCellAvatarsOption {
93
101
  export interface UseTableOptions {
94
102
  orders: string[]
95
103
  columns: TableColumns
96
- records?: MaybeRef<Record<string, any>[] | undefined>
97
- total?: MaybeRef<number | undefined>
98
- page?: MaybeRef<number | undefined>
99
- perPage?: MaybeRef<number | undefined>
104
+ records?: MaybeRef<Record<string, any>[] | null | undefined>
105
+ total?: MaybeRef<number | null | undefined>
106
+ page?: MaybeRef<number | null | undefined>
107
+ perPage?: MaybeRef<number | null | undefined>
100
108
  reset?: MaybeRef<boolean | undefined>
101
109
  borderless?: boolean
102
110
  loading?: MaybeRef<boolean | undefined>
@@ -1,8 +1,11 @@
1
1
  import dayjs, { ConfigType, Dayjs } from 'dayjs'
2
+ import RelativeTime from 'dayjs/plugin/relativeTime.js'
2
3
 
3
4
  export type Day = Dayjs
4
5
  export type Input = ConfigType
5
6
 
6
- export function day(input: Input): Dayjs {
7
+ dayjs.extend(RelativeTime)
8
+
9
+ export function day(input?: Input): Dayjs {
7
10
  return dayjs(input)
8
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "2.5.1",
3
+ "version": "2.7.0",
4
4
  "description": "Vue Components for Global Brain Design System.",
5
5
  "author": "Kia Ishii <ka.ishii@globalbrains.com>",
6
6
  "license": "MIT",
@@ -52,8 +52,8 @@
52
52
  "@types/markdown-it": "^12.2.3",
53
53
  "@types/node": "^18.8.0",
54
54
  "@vitejs/plugin-vue": "^3.1.2",
55
- "@vitest/coverage-c8": "^0.23.4",
56
- "@vue/test-utils": "^2.1.0",
55
+ "@vitest/coverage-c8": "^0.25.1",
56
+ "@vue/test-utils": "^2.2.1",
57
57
  "@vuelidate/core": "^2.0.0",
58
58
  "@vuelidate/validators": "^2.0.0",
59
59
  "@vueuse/core": "^9.3.0",
@@ -78,7 +78,7 @@
78
78
  "v-calendar": "3.0.0-alpha.8",
79
79
  "vite": "^3.1.4",
80
80
  "vitepress": "1.0.0-alpha.19",
81
- "vitest": "^0.23.4",
81
+ "vitest": "^0.25.1",
82
82
  "vue": "^3.2.40",
83
83
  "vue-router": "^4.1.5",
84
84
  "vue-tsc": "^1.0.8"