@globalbrain/sefirot 2.41.0 → 2.43.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.
@@ -1,17 +1,26 @@
1
1
  <script setup lang="ts">
2
+ import { computed } from 'vue'
2
3
  import { provideCardState } from '../composables/Card'
3
4
 
4
5
  export type Size = 'small' | 'medium' | 'large'
6
+ export type Mode = 'neutral' | 'info' | 'success' | 'warning' | 'danger'
5
7
 
6
- defineProps<{
8
+ const props = defineProps<{
7
9
  size?: Size
10
+ mode?: Mode
8
11
  }>()
9
12
 
10
13
  const { isCollapsed } = provideCardState()
14
+
15
+ const classes = computed(() => [
16
+ props.size,
17
+ props.mode ?? 'neutral',
18
+ { collapsed: isCollapsed.value }
19
+ ])
11
20
  </script>
12
21
 
13
22
  <template>
14
- <div class="SCard" :class="[size, { collapsed: isCollapsed }]">
23
+ <div class="SCard" :class="classes">
15
24
  <slot />
16
25
  </div>
17
26
  </template>
@@ -20,11 +29,17 @@ const { isCollapsed } = provideCardState()
20
29
  .SCard {
21
30
  display: grid;
22
31
  gap: 1px;
23
- border: 1px solid var(--c-divider-2);
32
+ border: 1px solid transparent;
24
33
  border-radius: 6px;
25
34
  background-color: var(--c-gutter);
26
35
  }
27
36
 
37
+ .SCard.neutral { border-color: var(--c-divider-2); }
38
+ .SCard.info { border-color: var(--c-info-border); }
39
+ .SCard.success { border-color: var(--c-success-border); }
40
+ .SCard.warning { border-color: var(--c-warning-border); }
41
+ .SCard.danger { border-color: var(--c-danger-border); }
42
+
28
43
  .SCard.collapsed {
29
44
  height: 48px;
30
45
  overflow: hidden;
@@ -1,5 +1,13 @@
1
+ <script setup lang="ts">
2
+ export type Mode = 'neutral' | 'info' | 'success' | 'warning' | 'danger'
3
+
4
+ defineProps<{
5
+ mode?: Mode
6
+ }>()
7
+ </script>
8
+
1
9
  <template>
2
- <p class="SCardHeaderTitle">
10
+ <p class="SCardHeaderTitle" :class="[mode ?? 'neutral']">
3
11
  <slot />
4
12
  </p>
5
13
  </template>
@@ -12,4 +20,10 @@
12
20
  font-size: 14px;
13
21
  font-weight: 600;
14
22
  }
23
+
24
+ .SCardHeaderTitle.neutral { color: var(--c-text-1); }
25
+ .SCardHeaderTitle.info { color: var(--c-info-text); }
26
+ .SCardHeaderTitle.success { color: var(--c-success-text); }
27
+ .SCardHeaderTitle.warning { color: var(--c-warning-text); }
28
+ .SCardHeaderTitle.danger { color: var(--c-danger-text); }
15
29
  </style>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, useSlots } from 'vue'
2
+ import { computed } from 'vue'
3
+ import { useSlotValue } from '../composables/Utils'
3
4
  import { type Day } from '../support/Day'
4
5
  import SDescEmpty from './SDescEmpty.vue'
5
6
 
@@ -8,13 +9,11 @@ const props = defineProps<{
8
9
  format?: string
9
10
  }>()
10
11
 
11
- const slots = useSlots()
12
+ const slotValue = useSlotValue()
12
13
 
13
14
  const _value = computed(() => {
14
- const slotValue = slots.default?.()[0].children
15
-
16
- if (typeof slotValue === 'string') {
17
- return slotValue
15
+ if (slotValue.value) {
16
+ return slotValue.value
18
17
  }
19
18
 
20
19
  if (props.value) {
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, useSlots } from 'vue'
2
+ import { computed } from 'vue'
3
+ import { useSlotValue } from '../composables/Utils'
3
4
  import SDescEmpty from './SDescEmpty.vue'
4
5
  import SLink from './SLink.vue'
5
6
 
@@ -8,27 +9,23 @@ const props = defineProps<{
8
9
  href?: string
9
10
  }>()
10
11
 
11
- const slots = useSlots()
12
+ const slotValue = useSlotValue()
12
13
 
13
14
  const link = computed(() => {
14
15
  if (props.href) {
15
16
  return props.href
16
17
  }
17
18
 
18
- const slotValue = slots.default?.()[0].children
19
-
20
- if (typeof slotValue === 'string') {
21
- return slotValue
22
- }
23
-
24
- return props.value
19
+ return slotValue.value
20
+ ? slotValue.value
21
+ : props.value
25
22
  })
26
23
  </script>
27
24
 
28
25
  <template>
29
- <div v-if="$slots.default || value" class="SDescLink">
26
+ <div v-if="slotValue || value" class="SDescLink">
30
27
  <SLink class="value" :href="link">
31
- <slot v-if="$slots.default" />
28
+ <slot v-if="slotValue" />
32
29
  <template v-else>{{ value }}</template>
33
30
  </SLink>
34
31
  </div>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, useSlots } from 'vue'
2
+ import { computed } from 'vue'
3
+ import { useSlotValue } from '../composables/Utils'
3
4
  import { format } from '../support/Num'
4
5
  import SDescEmpty from './SDescEmpty.vue'
5
6
 
@@ -8,12 +9,12 @@ const props = defineProps<{
8
9
  separator?: boolean
9
10
  }>()
10
11
 
11
- const slots = useSlots()
12
+ const slotValue = useSlotValue()
12
13
 
13
14
  const _value = computed(() => {
14
- const slotValue = slots.default?.()[0].children
15
+ const sv = slotValue.value
15
16
 
16
- const v = (typeof slotValue === 'string') ? Number(slotValue) : props.value
17
+ const v = sv ? Number(sv) : props.value
17
18
 
18
19
  if (v == null) {
19
20
  return null
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
+ import { useHasSlotContent } from '../composables/Utils'
3
4
  import SDescEmpty from './SDescEmpty.vue'
4
5
 
5
6
  const props = defineProps<{
@@ -13,13 +14,15 @@ const classes = computed(() => [
13
14
  { 'pre-wrap': props.preWrap }
14
15
  ])
15
16
 
17
+ const hasSlot = useHasSlotContent()
18
+
16
19
  const lineClamp = computed(() => props.lineClamp ?? 'none')
17
20
  </script>
18
21
 
19
22
  <template>
20
- <div v-if="$slots.default || value" class="SDescText" :class="classes">
23
+ <div v-if="hasSlot || value" class="SDescText" :class="classes">
21
24
  <div class="value">
22
- <slot v-if="$slots.default" />
25
+ <slot v-if="hasSlot" />
23
26
  <template v-else>{{ value }}</template>
24
27
  </div>
25
28
  </div>
@@ -50,6 +53,10 @@ const lineClamp = computed(() => props.lineClamp ?? 'none')
50
53
  }
51
54
  }
52
55
 
56
+ .value :deep(p + p) {
57
+ margin-top: 12px;
58
+ }
59
+
53
60
  .value :deep(a) {
54
61
  color: var(--c-info-text);
55
62
  transition: color 0.25s;
@@ -1,5 +1,13 @@
1
+ <script setup lang="ts">
2
+ export type Mode = 'neutral' | 'info' | 'success' | 'warning' | 'danger'
3
+
4
+ defineProps<{
5
+ mode?: Mode
6
+ }>()
7
+ </script>
8
+
1
9
  <template>
2
- <div class="SHeadTitle">
10
+ <div class="SHeadTitle" :class="[mode]">
3
11
  <slot />
4
12
  </div>
5
13
  </template>
@@ -11,4 +19,10 @@
11
19
  font-weight: 500;
12
20
  color: var(--c-text-1);
13
21
  }
22
+
23
+ .SHeadTitle.neutral { color: var(--c-text-1); }
24
+ .SHeadTitle.info { color: var(--c-info-text); }
25
+ .SHeadTitle.success { color: var(--c-success-text); }
26
+ .SHeadTitle.warning { color: var(--c-warning-text); }
27
+ .SHeadTitle.danger { color: var(--c-danger-text); }
14
28
  </style>
@@ -1,5 +1,6 @@
1
1
  import { type MaybeRefOrGetter, resolveUnref } from '@vueuse/core'
2
- import { type ComputedRef, computed } from 'vue'
2
+ import { type ComputedRef, computed, useSlots } from 'vue'
3
+ import { isArray, isString } from '../support/Utils'
3
4
 
4
5
  export type WhenCondition<T> = MaybeRefOrGetter<T>
5
6
 
@@ -33,3 +34,31 @@ export function computedArray<T = any>(fn: (arr: T[]) => void): ComputedRef<T[]>
33
34
  return arr
34
35
  })
35
36
  }
37
+
38
+ /**
39
+ * Checks whether the slot has a non empty value.
40
+ */
41
+ export function useHasSlotContent(name = 'default'): ComputedRef<boolean> {
42
+ const slots = useSlots()
43
+
44
+ return computed(() => {
45
+ return !!slots[name]?.().some((s) => {
46
+ return isArray(s.children) ? true : !!(s.children as string).trim()
47
+ })
48
+ })
49
+ }
50
+
51
+ /**
52
+ * Get the slot value. If the slot contains child nodes, it will get ignored
53
+ * and treated as if it was empty. This composable is useful to get the plain
54
+ * text out of the slot content.
55
+ */
56
+ export function useSlotValue(name = 'default'): ComputedRef<string | null> {
57
+ const slots = useSlots()
58
+
59
+ return computed(() => {
60
+ const c = slots[name]?.()[0]?.children
61
+ const v = isString(c) ? c.trim() : null
62
+ return v !== '' ? v : null
63
+ })
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "2.41.0",
3
+ "version": "2.43.0",
4
4
  "packageManager": "pnpm@8.6.2",
5
5
  "description": "Vue Components for Global Brain Design System.",
6
6
  "author": "Kia Ishii <ka.ishii@globalbrains.com>",