@teammodlr/ui-kit 2.1.6 → 2.1.8

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.
@@ -0,0 +1,48 @@
1
+ <template>
2
+ <div
3
+ @click="onClick"
4
+ :class="iconClass"
5
+ >
6
+ <template v-if="!hide">
7
+ <svg v-if="expanded" :class="style.icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
8
+ <path d="M12 8l10 8l-10 8z"></path>
9
+ </svg>
10
+ <svg v-else :class="style.icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
11
+ <path d="M12 8l10 8l-10 8z"></path>
12
+ </svg>
13
+ </template>
14
+ </div>
15
+ </template>
16
+
17
+ <script lang="ts">
18
+ import {computed, defineComponent, type PropType} from "vue";
19
+ import type {TmNode} from "./types";
20
+ import * as style from "./style";
21
+
22
+ export default defineComponent({
23
+ name: "TreeNodeToggle",
24
+ props: {
25
+ expanded: Boolean,
26
+ selected: Boolean,
27
+ onClick: Function as PropType<(e: MouseEvent) => void>,
28
+ hide: Boolean,
29
+ node: {
30
+ type: Object as PropType<TmNode>,
31
+ required: true
32
+ }
33
+ },
34
+ setup(props) {
35
+
36
+ const iconClass = computed(() => {
37
+ return {
38
+ [style.toggle]: true,
39
+ [style.iconRotate["90"]]: props.expanded,
40
+ }
41
+ });
42
+ return {
43
+ style,
44
+ iconClass
45
+ }
46
+ }
47
+ })
48
+ </script>
@@ -1,33 +1,13 @@
1
1
  <template>
2
- <MTree :data="data"/>
2
+ <MTree :data="data" label-field="name" key-field="id" @dblclick="dblclick" style="height: 300px;"/>
3
3
  </template>
4
4
  <script lang="ts" setup>
5
5
  import {ref} from 'vue'
6
- import type {TreeOption} from "../types";
6
+ import type {TmNode} from "../../../../lib/components/tree/types";
7
7
 
8
- function createData (level = 4, baseKey = ''): TreeOption[] | undefined {
9
- if (!level) return undefined
8
+ const data = ref([{"children":[{"children":[{"name":"Advertising & Marketing","weight":1,"type":"N","childrenCount":0,"id":"b5511a25-f9d4-402f-9f49-7bb9cff0bd97"},{"children":[],"name":"Finance","weight":1,"type":"N","childrenCount":0,"id":"b21ac382-ae7d-4cb0-b504-10a7ef6eac55"},{"children":[],"name":"Information Technology","weight":1,"type":"N","childrenCount":0,"id":"af71b879-0ea0-4cf6-8b70-4e764f08210b"},{"children":[],"name":"Legal","weight":1,"type":"N","childrenCount":0,"id":"c7d58cb8-d70c-4f70-99fb-7e8fdbb44b80"},{"children":[],"name":"Management","weight":1,"type":"N","childrenCount":0,"id":"2fef19d7-c744-4c36-9066-b077d1641f58"}],"name":"Cost Centers","weight":1,"type":"N","childrenCount":5,"id":"9bb9a4e9-749e-468a-9d39-d98625d8f3a1"},{"children":[{"children":[{"children":[{"children":[],"name":"Brisbane 01","weight":1,"type":"N","childrenCount":0,"id":"3beab845-9660-4cc3-8943-deb5672a72d1"},{"children":[],"name":"Brisbane 02","weight":1,"type":"N","childrenCount":0,"id":"812c3874-2103-4e35-b129-861811e9e582"},{"children":[],"name":"Brisbane 03","weight":1,"type":"N","childrenCount":0,"id":"df622e95-b7d9-41f5-9bd3-473bd0305b02"},{"children":[],"name":"Brisbane 04","weight":1,"type":"N","childrenCount":0,"id":"926b904c-4392-4bbb-b824-acaa1f62bb00"}],"name":"Queensland","weight":1,"type":"N","childrenCount":4,"id":"09661d2c-a90f-4c18-991b-d69500ffbdd5"},{"children":[{"children":[],"name":"Melbourne 01","weight":1,"type":"N","childrenCount":0,"id":"9ac3ce45-1bef-43dc-a3ac-227b1759b720"},{"children":[],"name":"Melbourne 02","weight":1,"type":"N","childrenCount":0,"id":"c66ec03a-431a-43e6-94aa-6b72dae73f98"},{"children":[],"name":"Melbourne 03","weight":1,"type":"N","childrenCount":0,"id":"3177b5e0-1b6e-4c7e-90bd-8e55b85880a4"},{"children":[],"name":"Melbourne 04","weight":1,"type":"N","childrenCount":0,"id":"88a1dd59-1b17-47fe-9a66-710cdff04a4f"},{"children":[],"name":"Melbourne 05","weight":1,"type":"N","childrenCount":0,"id":"400ac864-de9d-4afe-802e-880e41bb227c"}],"name":"Victoria","weight":1,"type":"N","childrenCount":5,"id":"063612b1-2cf3-47a6-a4c3-8fb552146d07"},{"children":[{"children":[],"name":"Sydney 01","weight":1,"type":"N","childrenCount":0,"id":"fed2081a-edf5-4823-bdc8-2860dd6e8a5d"},{"children":[],"name":"Sydney 02","weight":1,"type":"N","childrenCount":0,"id":"1b80744b-f2d3-4bbf-b4e5-63d9318d9538"},{"children":[],"name":"Sydney 03","weight":1,"type":"N","childrenCount":0,"id":"3aa2f7f7-8299-4ac9-95d8-d98f97cddda3"},{"children":[],"name":"Sydney 04","weight":1,"type":"N","childrenCount":0,"id":"657b512c-e77e-495a-bb75-bee4c8cd8ee0"},{"children":[],"name":"Sydney 05","weight":1,"type":"N","childrenCount":0,"id":"da5efcc4-3e88-4b5c-a0c5-7c096c5b83c5"},{"children":[],"name":"Sydney 06","weight":1,"type":"N","childrenCount":0,"id":"10fcae0f-3614-4e44-ace4-0c0423f19952"}],"name":"New South Wales","weight":1,"type":"N","childrenCount":6,"id":"3bdf2a0f-41ef-411c-9749-84301dd8088f"},{"children":[{"children":[],"name":"Perth 01","weight":1,"type":"N","childrenCount":0,"id":"0880d1ac-c7d3-4059-b0a8-25bed41496c7"},{"children":[],"name":"Perth 02","weight":1,"type":"N","childrenCount":0,"id":"0998eb28-769d-4a11-a609-10043a7d482f"}],"name":"Western Australia","weight":1,"type":"N","childrenCount":2,"id":"1b8c1791-fc09-4d2e-b681-cd58f027f2fe"},{"children":[{"children":[],"name":"Darwin 01","weight":1,"type":"N","childrenCount":0,"id":"068e40e2-6fde-4d65-a11c-357f694af697"},{"children":[],"name":"Darwin 02","weight":1,"type":"N","childrenCount":0,"id":"1411b083-7c4e-4810-b92e-372f521f2e7c"},{"children":[],"name":"Darwin 03","weight":1,"type":"N","childrenCount":0,"id":"4684a7ea-aabe-47d2-81fc-00d68196d3f6"},{"children":[],"name":"Darwin 04","weight":1,"type":"N","childrenCount":0,"id":"3fdd5254-639f-4efb-bd40-5c0dc5c1c314"}],"name":"Northern Territory","weight":1,"type":"N","childrenCount":4,"id":"c2ca2fa5-07ce-4529-8745-94567d785736"}],"name":"Australia","weight":1,"type":"N","childrenCount":5,"id":"70a043fc-e70c-4a30-8fbb-7784123c85a5"},{"children":[{"children":[],"name":"Auckland 01","weight":1,"type":"N","childrenCount":0,"id":"6293f121-f50e-42b4-a996-15263c45c3ee"},{"children":[],"name":"Auckland 02","weight":1,"type":"N","childrenCount":0,"id":"2cd3eda8-ab87-46da-8300-27261ee91d68"},{"children":[],"name":"Auckland 03","weight":1,"type":"N","childrenCount":0,"id":"88e6c0ae-e891-4faf-9b62-4270207fea91"},{"children":[],"name":"Wellington 01","weight":1,"type":"N","childrenCount":0,"id":"13ecbd3f-0b53-4a96-8627-07886173c8a6"},{"children":[],"name":"Wellington 02","weight":1,"type":"N","childrenCount":0,"id":"767b982c-ac81-44aa-90a3-b2f276919779"}],"name":"New Zealand","weight":1,"type":"N","childrenCount":5,"id":"c987df16-0757-4d04-97ec-386a423aef8d"},{"children":[],"name":"Online","weight":1,"type":"N","childrenCount":0,"id":"367a3afb-cc66-42d7-a022-f7f92683d768"}],"name":"Profit Centers","weight":1,"type":"N","childrenCount":3,"id":"782c9acf-dfdb-4e60-ace9-0f420aeecae6"}],"name":"All Departments","type":"N","childrenCount":2,"id":"a4b0784f-3d57-4a4d-a849-9700b27e6a6f"}]);
10
9
 
11
- const result: TreeOption[] = [];
12
- for (let index = 0; index < (20 - level); index++) {
13
- const key = '' + baseKey + level + index;
14
- result.push({
15
- label: createLabel(level),
16
- key,
17
- children: createData(level - 1, key)
18
- });
19
- }
20
-
21
- return result;
22
- }
23
-
24
- function createLabel (level: number): string {
25
- if (level === 4) return 'Out of Tao, One is born'
26
- if (level === 3) return 'Out of One, Two'
27
- if (level === 2) return 'Out of Two, Three'
28
- if (level === 1) return 'Out of Three, the created universe'
29
- return ''
10
+ function dblclick(node: TmNode) {
11
+ console.log(node);
30
12
  }
31
-
32
- const data = ref(createData());
33
13
  </script>
@@ -1,5 +1,12 @@
1
1
  import type {ExtractPublicPropTypes, PropType} from "vue";
2
- import type {TreeOptions, Key, TreeNodeProps, OnUpdateIndeterminateKeys, onUpdateExpandedKeys} from "./types";
2
+ import type {
3
+ TreeOptions,
4
+ Key,
5
+ TreeNodeProps,
6
+ OnUpdateIndeterminateKeys,
7
+ onUpdateExpandedKeys,
8
+ TreeNodeDoubleClick
9
+ } from "./types";
3
10
  import type {TreeMateOptions} from "treemate";
4
11
  import type {MaybeArray} from "../../call";
5
12
 
@@ -18,6 +25,7 @@ export const treeSharedProps = {
18
25
  type: String,
19
26
  default: 'children',
20
27
  },
28
+ onDblClick: Function as PropType<TreeNodeDoubleClick>,
21
29
  onUpdateIndeterminateKeys: [Function, Array] as PropType<
22
30
  MaybeArray<OnUpdateIndeterminateKeys>
23
31
  >,
@@ -0,0 +1,70 @@
1
+ import {createVar, globalKeyframes, globalStyle, style, styleVariants} from "@vanilla-extract/css";
2
+ import {themeVars} from "../../../styles/theme.css";
3
+
4
+
5
+ export const toggle = style({
6
+ cursor: "pointer",
7
+ display: "inline-flex",
8
+ flexShrink: 0,
9
+ height: `24px`,
10
+ width: `24px`,
11
+ alignItems: "center",
12
+ justifyContent: "center",
13
+ verticalAlign: "bottom",
14
+ transition: `transform .15s ${themeVars.transition.default}`
15
+ })
16
+ export const icon = style({
17
+ position: "relative",
18
+ height: `14px`,
19
+ width: `14px`,
20
+ display: "flex",
21
+ fontSize: `14px`,
22
+ fill: "currentColor",
23
+ color: themeVars.color.gray["600"],
24
+ });
25
+
26
+ export const iconRotate = styleVariants({
27
+ 90: {
28
+ transform: `rotate(90deg)`,
29
+ }
30
+ });
31
+
32
+ export const nodeWrapper = style({
33
+ boxSizing: "border-box",
34
+ padding: `${themeVars.space["0.5"]} 0`,
35
+ })
36
+
37
+ export const node = style({
38
+ transform: `translate3d(0, 0, 0)`,
39
+ position: "relative",
40
+ display: "flex",
41
+ borderRadius: themeVars.rounded.small,
42
+ transition: `background-color .3s ${themeVars.transition.default}`,
43
+ selectors: {
44
+ [`&:hover`]: {
45
+ backgroundColor: themeVars.color.gray["150"]
46
+ }
47
+ }
48
+ })
49
+
50
+ export const nodeContent = style({
51
+ cursor: "pointer",
52
+ position: "relative",
53
+ display: "inline-flex",
54
+ alignItems: "center",
55
+ minHeight: `24px`,
56
+ boxSizing: "border-box",
57
+ verticalAlign: "bottom",
58
+ padding: `0 ${themeVars.space["1"]} 0 ${themeVars.space["1"]}`,
59
+ borderRadius: themeVars.rounded.default,
60
+ lineHeight: 1.5,
61
+ userSelect: "none",
62
+ flexGrow: 1
63
+ });
64
+
65
+ export const nodeContentText = style({
66
+ flexGrow: 1,
67
+ maxWidth: `100%`,
68
+ fontSize: themeVars.fontSize.base,
69
+ color: themeVars.color.gray["700"],
70
+ })
@@ -0,0 +1 @@
1
+ export * from './Tree.css';
@@ -13,15 +13,24 @@ export interface TreeOptionBase {
13
13
  export type TreeOption = TreeOptionBase & Record<string, unknown>;
14
14
  export type TreeOptions = TreeOption[];
15
15
 
16
- export type TreeNodeProps = (info: {
16
+ export type TreeNodeProps = (
17
+ node: TreeOption,
18
+ ) => HTMLAttributes & Record<string, unknown>;
19
+
20
+ export type TreeNodeDoubleClick = (info: {
17
21
  option: TreeOption,
18
- }) => HTMLAttributes & Record<string, unknown>;
22
+ }) => void;
19
23
 
20
24
  export interface TreeInjection {
25
+ mergedExpandedKeysRef: Ref<Key[]>,
21
26
  indentRef: Ref<number>,
22
27
  expandOnClickRef: Ref<boolean>,
23
28
  nodePropsRef: Ref<TreeNodeProps | undefined>,
24
- handleSwitcherClick: (node: TreeNode<TreeOption>) => void
29
+ labelFieldRef: Ref<string>,
30
+ keyFieldRef: Ref<string>,
31
+ childrenFieldRef: Ref<string>,
32
+ handleToggleClick: (node: TreeNode<TreeOption>) => void,
33
+ handleDoubleClick: (node: TreeOption) => void,
25
34
  }
26
35
 
27
36
  export const treeInjectionKey = createInjectionKey<TreeInjection>('tree')