@hyvor/design 1.1.13 → 1.1.14

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,23 +3,27 @@
3
3
  import ActionListItem from '../ActionList/ActionListItem.svelte';
4
4
  import Dropdown from '../Dropdown/Dropdown.svelte';
5
5
  import IconBoxArrowUpRight from '@hyvor/icons/IconBoxArrowUpRight';
6
- import { barUser } from './bar.js';
7
6
  import BarUserPreview from './BarUserPreview.svelte';
7
+ import BarUserPicture from './BarUserPicture.svelte';
8
8
 
9
9
  interface Props {
10
10
  instance: string;
11
+ logoutUrl?: string;
12
+ cloud: boolean;
11
13
  }
12
14
 
13
- let { instance }: Props = $props();
15
+ let {
16
+ instance,
17
+ logoutUrl = `${instance}/account/logout`,
18
+ cloud,
19
+ }: Props = $props();
14
20
  </script>
15
21
 
16
22
  <div class="wrap">
17
23
  <Dropdown align="end" width={325}>
18
24
  {#snippet trigger()}
19
25
  <button class="user-wrap">
20
- {#if $barUser}
21
- <img class="user-picture" src={$barUser?.picture_url} alt={$barUser?.name} />
22
- {/if}
26
+ <BarUserPicture />
23
27
  </button>
24
28
  {/snippet}
25
29
 
@@ -27,15 +31,19 @@
27
31
  <ActionList>
28
32
  <BarUserPreview />
29
33
 
30
- <a href="{instance}/account" target="_blank">
31
- <ActionListItem>
32
- Manage Account
33
- {#snippet end()}
34
- <IconBoxArrowUpRight size={12} />
35
- {/snippet}
36
- </ActionListItem>
37
- </a>
38
- <a href="{instance}/account/logout">
34
+ {#if cloud}
35
+ <a href="{instance}/account" target="_blank">
36
+ <ActionListItem>
37
+ Manage Account
38
+ {#snippet end()}
39
+ <IconBoxArrowUpRight size={12} />
40
+ {/snippet}
41
+ </ActionListItem>
42
+ </a>
43
+ {/if}
44
+
45
+
46
+ <a href="{logoutUrl}">
39
47
  <ActionListItem>Logout</ActionListItem>
40
48
  </a>
41
49
  </ActionList>
@@ -65,8 +73,4 @@
65
73
  .user-wrap:hover {
66
74
  box-shadow: 0 0 0 4px var(--input);
67
75
  }
68
- img {
69
- width: 100%;
70
- height: 100%;
71
- }
72
76
  </style>
@@ -1,5 +1,7 @@
1
1
  interface Props {
2
2
  instance: string;
3
+ logoutUrl?: string;
4
+ cloud: boolean;
3
5
  }
4
6
  declare const BarUser: import("svelte").Component<Props, {}, "">;
5
7
  type BarUser = ReturnType<typeof BarUser>;
@@ -0,0 +1,33 @@
1
+ <script lang="ts">
2
+ import { barUser } from "./bar.js";
3
+ </script>
4
+
5
+
6
+ {#if $barUser}
7
+ {#if $barUser.picture_url}
8
+ <img src={$barUser.picture_url} alt={$barUser.name} />
9
+ {:else}
10
+ <span class="user-placeholder">
11
+ {$barUser.name ? $barUser.name[0].toUpperCase() : '?'}
12
+ </span>
13
+ {/if}
14
+ {/if}
15
+
16
+ <style>
17
+ img {
18
+ width: 30px;
19
+ height: 30px;
20
+ border-radius: 50%;
21
+ }
22
+ .user-placeholder {
23
+ display: inline-flex;
24
+ align-items: center;
25
+ justify-content: center;
26
+ width: 30px;
27
+ height: 30px;
28
+ border-radius: 50%;
29
+ color: var(--text);
30
+ font-size: 14px;
31
+ background-color: var(--input);
32
+ }
33
+ </style>
@@ -0,0 +1,18 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const BarUserPicture: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type BarUserPicture = InstanceType<typeof BarUserPicture>;
18
+ export default BarUserPicture;
@@ -1,14 +1,21 @@
1
1
  <script lang="ts">
2
2
  import { barUser } from './bar.js';
3
+ import BarUserPicture from './BarUserPicture.svelte';
3
4
  </script>
4
5
 
5
6
  {#if $barUser}
6
7
  <div class="preview">
7
8
  <div class="left">
8
- <img src={$barUser.picture_url} alt={$barUser.name} />
9
+ <BarUserPicture />
9
10
  </div>
10
11
  <div class="right">
11
- <div class="username">@{$barUser.username}</div>
12
+ <div class="username">
13
+ {#if $barUser.username}
14
+ @{$barUser.username}
15
+ {:else if $barUser.name}
16
+ {$barUser.name}
17
+ {/if}
18
+ </div>
12
19
  <div class="email">{$barUser.email}</div>
13
20
  </div>
14
21
  </div>
@@ -3,7 +3,7 @@
3
3
  import { onMount } from 'svelte';
4
4
  import BarProducts, { PRODUCTS } from './BarProducts.svelte';
5
5
  import BarSupport from './BarSupport.svelte';
6
- import { loadBarUser, setInstanceAndProduct, type BarConfig, type BarProduct } from './bar.js';
6
+ import { barUser, initBar, setInstanceAndProduct, type BarConfig, type BarUser as BarUserType } from './bar.js';
7
7
  import BarUpdates from './BarUpdates.svelte';
8
8
  import IconCaretDownFill from '@hyvor/icons/IconCaretDownFill';
9
9
  import BarNotice from './Notice/BarNotice.svelte';
@@ -13,9 +13,31 @@
13
13
  instance?: string;
14
14
  product: string;
15
15
  config?: Partial<BarConfig>;
16
+
17
+ // set a custom logo URL
18
+ // defaults to instance + '/api/public/logo/' + product + '.svg'
19
+ // recommended to use this for self-hostable products
20
+ logo?: string;
21
+
22
+ /**
23
+ * Whether it is a HYVOR cloud-hosted product.
24
+ * If false, we will hide some features
25
+ */
26
+ cloud?: boolean;
27
+ authOverride?: {
28
+ user: BarUserType | null;
29
+ logoutUrl: string;
30
+ }
16
31
  }
17
32
 
18
- let { instance = 'https://hyvor.com', product, config = {} }: Props = $props();
33
+ let {
34
+ instance = 'https://hyvor.com',
35
+ product,
36
+ logo = `${instance}/api/public/logo/${product}.svg`,
37
+ config = {},
38
+ cloud = true,
39
+ authOverride = undefined
40
+ }: Props = $props();
19
41
 
20
42
  let mobileShow = $state(false);
21
43
 
@@ -41,7 +63,14 @@
41
63
 
42
64
  onMount(() => {
43
65
  setInstanceAndProduct(instance, product);
44
- loadBarUser();
66
+
67
+ if (cloud) {
68
+ initBar();
69
+ } else {
70
+ if (authOverride) {
71
+ barUser.set(authOverride.user);
72
+ }
73
+ }
45
74
  });
46
75
 
47
76
  function getName() {
@@ -59,7 +88,7 @@
59
88
  <div class="left">
60
89
  <a class="logo" href="/">
61
90
  <img
62
- src={instance + '/api/public/logo/' + product + '.svg'}
91
+ src={logo}
63
92
  alt={product}
64
93
  width="20"
65
94
  height="20"
@@ -74,16 +103,20 @@
74
103
  <BarNotice {instance} />
75
104
 
76
105
  <div class="hidden-on-mobile">
77
- <BarSupport config={configComplete} {product} mobile={mobileShow} />
78
- <BarProducts {instance} mobile={mobileShow} />
79
- <BarUpdates {instance} {product} />
106
+ {#if cloud}
107
+ <BarSupport config={configComplete} {product} mobile={mobileShow} />
108
+ <BarProducts {instance} mobile={mobileShow} />
109
+ <BarUpdates {instance} {product} />
110
+ {/if}
80
111
  </div>
81
112
 
82
- <div class="mobile">
83
- <IconCaretDownFill />
84
- </div>
113
+ {#if cloud}
114
+ <div class="mobile">
115
+ <IconCaretDownFill />
116
+ </div>
117
+ {/if}
85
118
 
86
- <BarUser {instance} />
119
+ <BarUser {instance} logoutUrl={authOverride?.logoutUrl} {cloud} />
87
120
  </div>
88
121
  </div>
89
122
 
@@ -1,8 +1,18 @@
1
- import { type BarConfig } from './bar.js';
1
+ import { type BarConfig, type BarUser as BarUserType } from './bar.js';
2
2
  interface Props {
3
3
  instance?: string;
4
4
  product: string;
5
5
  config?: Partial<BarConfig>;
6
+ logo?: string;
7
+ /**
8
+ * Whether it is a HYVOR cloud-hosted product.
9
+ * If false, we will hide some features
10
+ */
11
+ cloud?: boolean;
12
+ authOverride?: {
13
+ user: BarUserType | null;
14
+ logoutUrl: string;
15
+ };
6
16
  }
7
17
  declare const HyvorBar: import("svelte").Component<Props, {}, "">;
8
18
  type HyvorBar = ReturnType<typeof HyvorBar>;
@@ -5,11 +5,11 @@ export interface BarConfig {
5
5
  chat: boolean;
6
6
  g2: string | null;
7
7
  }
8
- interface BarUser {
8
+ export interface BarUser {
9
9
  name: string | null;
10
- username: string;
10
+ username?: string | null;
11
11
  email: string;
12
- picture_url: string;
12
+ picture_url: string | null;
13
13
  }
14
14
  export interface BarUpdate {
15
15
  id: number;
@@ -34,7 +34,7 @@ export declare const barUnreadUpdates: import("svelte/store").Writable<number>;
34
34
  export declare const barLicense: import("svelte/store").Writable<BarResolvedLicense | null>;
35
35
  export declare const barHasFailedInvoices: import("svelte/store").Writable<boolean>;
36
36
  export declare function setInstanceAndProduct(instance_: string, product_: string): void;
37
- export declare function loadBarUser(): void;
37
+ export declare function initBar(): void;
38
38
  export declare class UnreadUpdatesTimeLocalStorage {
39
39
  static KEY: string;
40
40
  static get(): number | null;
@@ -49,4 +49,3 @@ export declare const bar: {
49
49
  */
50
50
  reload: () => void;
51
51
  };
52
- export {};
@@ -9,7 +9,7 @@ export function setInstanceAndProduct(instance_, product_) {
9
9
  instance = instance_;
10
10
  product = product_;
11
11
  }
12
- export function loadBarUser() {
12
+ export function initBar() {
13
13
  const query = new URLSearchParams();
14
14
  query.set('product', product);
15
15
  const lastUnreadTime = UnreadUpdatesTimeLocalStorage.get();
@@ -90,6 +90,6 @@ export const bar = {
90
90
  * This is useful to create after, for example, a user creates a new blog
91
91
  */
92
92
  reload: () => {
93
- loadBarUser();
93
+ initBar();
94
94
  }
95
95
  };
package/package.json CHANGED
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "version": "1.1.13"
62
+ "version": "1.1.14"
63
63
  }