tera-system-ui 0.1.15 → 0.1.17

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.
@@ -5,13 +5,12 @@ export interface TabsProps extends TabsVariants {
5
5
  children?: any;
6
6
  class?: string;
7
7
  value?: string;
8
+ onchange?: (value: string) => void;
8
9
  }
9
10
  export type TabsContext = {
10
- setValue: (value: string) => void;
11
- getValue: () => string | undefined;
12
- currentTab?: any;
13
- state: any;
11
+ currentTab?: string;
12
+ onchange: (value: string) => void;
14
13
  };
15
14
  export declare function getCtx(): TabsContext;
16
- export declare function setCtx(context: TabsContext): void;
15
+ export declare function createContext(context: TabsContext): void;
17
16
  export {};
@@ -0,0 +1,26 @@
1
+ import { tv } from "tailwind-variants";
2
+ import { getContext, setContext } from "svelte";
3
+ export const styles = tv({
4
+ base: '',
5
+ variants: {},
6
+ compoundVariants: [],
7
+ defaultVariants: {},
8
+ });
9
+ const CONTEXT_NAME = 'Tabs';
10
+ export function getCtx() {
11
+ return getContext(CONTEXT_NAME);
12
+ }
13
+ export function createContext(context) {
14
+ let currentTab = $state(context.currentTab);
15
+ setContext(CONTEXT_NAME, {
16
+ get currentTab() {
17
+ return currentTab;
18
+ },
19
+ set currentTab(value) {
20
+ if (value !== currentTab) {
21
+ context.onchange(value);
22
+ currentTab = value;
23
+ }
24
+ },
25
+ });
26
+ }
@@ -1,48 +1,33 @@
1
1
  <script lang="ts">
2
- import {setCtx, type TabsProps} from "../Tabs";
2
+ import {createContext, getCtx, type TabsProps} from "../Tabs.svelte";
3
3
  import {cn} from "../../../utils/utils";
4
- import {createTabs} from "../tabs.svelte";
5
- import {untrack} from "svelte";
6
4
 
7
5
  let {
8
6
  children,
9
7
  value = $bindable(),
10
8
  class: className,
9
+ onchange,
11
10
  ...props
12
11
  }: TabsProps = $props();
13
12
 
14
-
15
- function setValue(v: string) {
16
- // console.log('Change value', v)
17
- value = v
18
- }
19
-
20
- function getValue() {
21
- return value
13
+ function onTabChange(currentTab: string) {
14
+ onchange?.(currentTab)
15
+ value = currentTab
22
16
  }
23
17
 
24
- let tabsState = createTabs(value)
25
-
26
- setCtx({
27
- setValue: setValue,
28
- getValue: getValue,
18
+ createContext({
29
19
  currentTab: value,
30
- state: tabsState
20
+ onchange: onTabChange
31
21
  })
32
22
 
33
- $effect(() => {
34
- value = tabsState.currentTab
35
- })
23
+ const context = getCtx()
36
24
 
37
25
  $effect(() => {
38
- tabsState.currentTab = value
26
+ context.currentTab = value
39
27
  })
40
-
41
- let tabs = $state()
42
28
  </script>
43
29
 
44
- <div bind:this={tabs}
45
- data-tabs-root
30
+ <div data-tabs-root
46
31
  class={cn("grid grid-rows-[auto_1fr] max-h-full gap-2", className)}>
47
32
  {@render children?.()}
48
33
  </div>
@@ -1,4 +1,4 @@
1
- import { type TabsProps } from "../Tabs";
1
+ import { type TabsProps } from "../Tabs.svelte";
2
2
  declare const Tabs: import("svelte").Component<TabsProps, {}, "value">;
3
3
  type Tabs = ReturnType<typeof Tabs>;
4
4
  export default Tabs;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import {getCtx} from "../Tabs";
2
+ import {getCtx} from "../Tabs.svelte";
3
3
  import {cn} from "../../../utils/utils";
4
4
 
5
5
  let {
@@ -19,7 +19,7 @@
19
19
  <div
20
20
  role="tabpanel"
21
21
  data-value={value}
22
- data-state={context.state.currentTab === value ? 'active' : 'inactive'}
22
+ data-state={context.currentTab === value ? 'active' : 'inactive'}
23
23
  class={cn("bg-neutral-token-1 overflow-auto", className)}>
24
24
  {@render children?.()}
25
25
  </div>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import {cn} from "../../../utils/utils";
3
- import {getCtx} from "../Tabs";
3
+ import {getCtx} from "../Tabs.svelte";
4
4
 
5
5
  let {
6
6
  children,
@@ -16,10 +16,10 @@
16
16
  <div>
17
17
  <button class={cn("tab-button font-semibold px-2.5 py-1.5 text-neutral-token-8 hover:text-primary-token-4")}
18
18
  data-value={value}
19
- data-state={value === context.state.currentTab ? 'active' : 'inactive'}
19
+ data-state={value === context.currentTab ? 'active' : 'inactive'}
20
20
  onclick={() => {
21
- context.state.currentTab = value
22
- }}
21
+ context.currentTab = value
22
+ }}
23
23
  >
24
24
  {@render children?.()}
25
25
  </button>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import {cn, consoleLog, observeVisibility} from "../../../utils/utils";
3
- import {getCtx} from "../Tabs";
3
+ import {getCtx} from "../Tabs.svelte";
4
4
  import {onMount} from "svelte";
5
5
 
6
6
  let {
@@ -13,7 +13,7 @@
13
13
  let tabsList = $state()
14
14
 
15
15
  function updateIndicator() {
16
- let button = tabsList?.querySelector(`button[data-value="${context.state.currentTab}"]`)
16
+ let button = tabsList?.querySelector(`button[data-value="${context.currentTab}"]`)
17
17
 
18
18
  const rect = button.getBoundingClientRect();
19
19
  const containerRect = tabsList.getBoundingClientRect();
@@ -24,21 +24,20 @@
24
24
  tabIndicator.style.left = `${left}px`;
25
25
  tabIndicator.style.width = `${width}px`;
26
26
 
27
- consoleLog('TabList', 'tabIndicator', tabIndicator)
27
+ // consoleLog('TabList', 'tabIndicator', tabIndicator)
28
28
  }
29
29
 
30
30
 
31
31
  let context = getCtx()
32
32
 
33
33
  $effect(() => {
34
- context.state.currentTab
34
+ context.currentTab
35
35
  updateIndicator();
36
36
  })
37
37
 
38
38
  onMount(() => {
39
39
  const stopObserving = observeVisibility(tabIndicator, (isVisible, entry) => {
40
40
  if (isVisible) {
41
- consoleLog('Element is visible:', entry.target);
42
41
  updateIndicator()
43
42
  }
44
43
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tera-system-ui",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run customPrepublish && npm run generate-index && vite build && npm run package && npm run postpublish",
@@ -1,15 +0,0 @@
1
- import { tv } from "tailwind-variants";
2
- import { getContext, setContext } from "svelte";
3
- export const styles = tv({
4
- base: '',
5
- variants: {},
6
- compoundVariants: [],
7
- defaultVariants: {},
8
- });
9
- const CONTEXT_NAME = 'Tabs';
10
- export function getCtx() {
11
- return getContext(CONTEXT_NAME);
12
- }
13
- export function setCtx(context) {
14
- setContext(CONTEXT_NAME, context);
15
- }