whelk-ui 0.0.2 → 0.0.3

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.
Files changed (30) hide show
  1. package/README.md +2 -0
  2. package/package.json +4 -3
  3. package/playwright.config.ts +79 -0
  4. package/src/components/add_object/AddObject.vue +40 -0
  5. package/src/components/card/CardComponent.vue +14 -0
  6. package/src/components/card/card_footer/CardFooter.vue +19 -0
  7. package/src/components/card/card_header/CardHeader.vue +16 -0
  8. package/src/components/check_box/CheckBox.vue +42 -0
  9. package/src/components/datetime/DatetimeComponent.vue +147 -0
  10. package/src/components/drop_down/DropDown.vue +104 -0
  11. package/src/components/drop_down/drop_down_item/DropDownItem.vue +58 -0
  12. package/src/components/form_group/FormGroup.spec.ts +16 -0
  13. package/src/components/form_group/FormGroup.vue +19 -0
  14. package/src/components/number_input/NumberInput.spec.ts +712 -0
  15. package/src/components/number_input/NumberInput.vue +264 -0
  16. package/src/components/password_input/PasswordInput.vue +166 -0
  17. package/src/components/render_error_message/RenderErrorMessage.spec.ts +0 -0
  18. package/src/components/render_error_message/RenderErrorMessage.vue +32 -0
  19. package/src/components/switch/SwitchComponent.vue +152 -0
  20. package/src/components/text_area/TextArea.vue +151 -0
  21. package/src/components/text_input/TextInput.vue +178 -0
  22. package/src/components/tool_tip/ToolTip.vue +96 -0
  23. package/src/utils/enums/ObjectTitleCaseEnums.ts +17 -0
  24. package/src/utils/enums/ObjectTypeEnums.ts +15 -0
  25. package/src/utils/interfaces/DocumentItemInterface.ts +5 -0
  26. package/src/utils/interfaces/DropDownItemsInterface.ts +8 -0
  27. package/src/utils/interfaces/FolderItemInterface.ts +4 -0
  28. package/src/utils/interfaces/MenuItemInterface.ts +10 -0
  29. package/tests/example.spec.ts +18 -0
  30. package/vite.config.ts +40 -1
@@ -0,0 +1,151 @@
1
+ <script setup lang="ts">
2
+ import FormGroup from '../form_group/FormGroup.vue';
3
+ import { computed, ref } from 'vue';
4
+ import RenderErrorMessage from '../render_error_message/RenderErrorMessage.vue';
5
+ import ToolTip from '../tool_tip/ToolTip.vue';
6
+
7
+ // Define Emits
8
+ const emit = defineEmits(['isValid']);
9
+
10
+ // Define Props
11
+ const props = defineProps({
12
+ isRequired: {
13
+ type: Boolean,
14
+ default: false,
15
+ },
16
+ label: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ minLength: {
21
+ type: Number,
22
+ default: 0,
23
+ required: false,
24
+ validator: (val) => !Number.isNaN(val),
25
+ },
26
+ maxLength: {
27
+ type: Number,
28
+ default: 0,
29
+ required: false,
30
+ validator: (val) => !Number.isNaN(val),
31
+ },
32
+ placeholderText: {
33
+ type: String,
34
+ required: false,
35
+ default: '',
36
+ },
37
+ tooltipMessage: {
38
+ type: String,
39
+ required: false,
40
+ default: '',
41
+ },
42
+ tooltipTitle: {
43
+ type: String,
44
+ required: false,
45
+ default: '',
46
+ },
47
+ });
48
+
49
+ // Define Models
50
+ const model = defineModel('model', {
51
+ type: String,
52
+ required: false,
53
+ default: '',
54
+ });
55
+
56
+ // Define ref
57
+ const hasError = ref(false);
58
+ const errorMessage = ref('');
59
+
60
+ // Computed
61
+ const getId = computed(() => {
62
+ // Return an id made up of input- + title
63
+ return 'input-' + props.label?.toLowerCase()?.replace(' ', '-');
64
+ });
65
+
66
+ function checkValidation() {
67
+ // Fall back to defaults
68
+ hasError.value = false;
69
+ errorMessage.value = '';
70
+
71
+ // Get the length of the model and if NaN fallback to 0
72
+ let modelLength: number = Number(model?.value?.toString().length);
73
+ modelLength = isNaN(modelLength) ? 0 : modelLength;
74
+
75
+ // Check the first "required" condition
76
+ if (props.isRequired && modelLength === 0) {
77
+ hasError.value = true;
78
+ errorMessage.value = 'This field is required';
79
+ }
80
+
81
+ // Check the minimum "required" condition
82
+ if (props.minLength > 0 && modelLength < props.minLength) {
83
+ hasError.value = true;
84
+ errorMessage.value = `This field has a minimum length ${modelLength} / ${props.minLength}`;
85
+ }
86
+
87
+ // Check the maximum "required" condition
88
+ if (props.maxLength > 0 && modelLength > props.maxLength) {
89
+ hasError.value = true;
90
+ errorMessage.value = `This field has a maximum length ${modelLength} / ${props.maxLength}`;
91
+ }
92
+
93
+ // Set the defined ref and tell parent
94
+ emit('isValid', !hasError.value);
95
+ }
96
+ </script>
97
+
98
+ <template>
99
+ <FormGroup>
100
+ <label :for="getId">
101
+ <ToolTip
102
+ v-if="props.tooltipMessage !== ''"
103
+ :title="tooltipTitle"
104
+ :message="tooltipMessage"
105
+ :id="getId"
106
+ />
107
+ {{ label
108
+ }}<span v-if="isRequired" aria-description="Field is required"
109
+ >*</span
110
+ >
111
+ </label>
112
+ <textarea
113
+ rows="10"
114
+ :id="getId"
115
+ type="text"
116
+ :name="props.label"
117
+ :placeholder="props.placeholderText"
118
+ v-model="model"
119
+ v-on:keyup="checkValidation"
120
+ v-on:focusout="checkValidation"
121
+ />
122
+ <RenderErrorMessage :error-message="errorMessage" />
123
+ </FormGroup>
124
+ </template>
125
+
126
+ <style scoped>
127
+ label {
128
+ margin-bottom: 6px;
129
+ }
130
+
131
+ span {
132
+ color: var(--text-red);
133
+ }
134
+
135
+ textarea {
136
+ border-style: var(--border-style);
137
+ border-width: var(--border-width);
138
+ border-radius: var(--border-radius);
139
+ border-color: var(--border);
140
+ box-sizing: border-box;
141
+ -moz-box-sizing: border-box;
142
+ -webkit-box-sizing: border-box;
143
+
144
+ &:focus {
145
+ border-color: var(--secondary);
146
+ border-width: 2px;
147
+ outline: none;
148
+ padding: calc(0.5rem - 1px);
149
+ }
150
+ }
151
+ </style>
@@ -0,0 +1,178 @@
1
+ <script setup lang="ts">
2
+ import FormGroup from '../form_group/FormGroup.vue';
3
+ import {computed, ref} from 'vue';
4
+ import RenderErrorMessage from '../render_error_message/RenderErrorMessage.vue';
5
+ import ToolTip from '../tool_tip/ToolTip.vue';
6
+
7
+ // Define Emits
8
+ const emit = defineEmits(['isValid']);
9
+
10
+ // Define Props
11
+ const props = defineProps({
12
+ isRequired: {
13
+ type: Boolean,
14
+ default: false,
15
+ },
16
+ label: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ minLength: {
21
+ type: Number,
22
+ default: 0,
23
+ required: false,
24
+ validator: (val) => !Number.isNaN(val),
25
+ },
26
+ maxLength: {
27
+ type: Number,
28
+ default: 0,
29
+ required: false,
30
+ validator: (val) => !Number.isNaN(val),
31
+ },
32
+ placeholderText: {
33
+ type: String,
34
+ required: false,
35
+ default: '',
36
+ },
37
+ tooltipMessage: {
38
+ type: String,
39
+ required: false,
40
+ default: '',
41
+ },
42
+ tooltipTitle: {
43
+ type: String,
44
+ required: false,
45
+ default: '',
46
+ },
47
+ });
48
+
49
+ // Define Models
50
+ const model = defineModel({ required: true });
51
+
52
+ // Define ref
53
+ const hasError = ref(false);
54
+ const errorMessage = ref('');
55
+
56
+ // Computed
57
+ const getId = computed(() => {
58
+ // Return an id made up of input- + title
59
+ return 'input-' + props.label?.toLowerCase()?.replace(' ', '-');
60
+ });
61
+
62
+ function checkValidation() {
63
+ // Fall back to defaults
64
+ hasError.value = false;
65
+ errorMessage.value = '';
66
+
67
+ // Get the length of the model and if NaN fallback to 0
68
+ let modelLength: number = Number(model?.value?.toString().length);
69
+ modelLength = isNaN(modelLength) ? 0 : modelLength;
70
+
71
+ // Check the first "required" condition
72
+ if (props.isRequired && modelLength === 0) {
73
+ hasError.value = true;
74
+ errorMessage.value = 'This field is required';
75
+ }
76
+
77
+ // Check the minimum "required" condition
78
+ if (props.minLength > 0 && modelLength < props.minLength) {
79
+ hasError.value = true;
80
+ errorMessage.value = `This field has a minimum length ${modelLength} / ${props.minLength}`;
81
+ }
82
+
83
+ // Check the maximum "required" condition
84
+ if (props.maxLength > 0 && modelLength > props.maxLength) {
85
+ hasError.value = true;
86
+ errorMessage.value = `This field has a maximum length ${modelLength} / ${props.maxLength}`;
87
+ }
88
+
89
+ // Set the defined ref and tell parent
90
+ emit('isValid', !hasError.value);
91
+ }
92
+ </script>
93
+
94
+ <template>
95
+ <FormGroup class="text-input">
96
+ <label :for="getId">
97
+ <ToolTip
98
+ v-if="props.tooltipMessage !== ''"
99
+ :title="tooltipTitle"
100
+ :message="tooltipMessage"
101
+ :id="getId"
102
+ />
103
+ {{
104
+ label
105
+ }}<span v-if="isRequired" aria-description="Field is required"
106
+ >*</span
107
+ >
108
+ </label>
109
+ <input
110
+ :id="getId"
111
+ type="text"
112
+ :name="props.label"
113
+ :placeholder="props.placeholderText"
114
+ v-model="model"
115
+ v-on:keyup="checkValidation"
116
+ v-on:focusout="checkValidation"
117
+ />
118
+ <RenderErrorMessage :error-message="errorMessage"/>
119
+ </FormGroup>
120
+ </template>
121
+
122
+ <style scoped>
123
+ .text-input {
124
+
125
+ > label {
126
+ margin-bottom: 6px;
127
+ }
128
+
129
+ > span {
130
+ color: var(--text-red);
131
+ }
132
+
133
+ > input {
134
+ border-style: var(--border-style);
135
+ border-width: var(--border-width);
136
+ border-radius: var(--border-radius);
137
+ border-color: var(--border);
138
+ box-sizing: border-box;
139
+ -moz-box-sizing: border-box;
140
+ -webkit-box-sizing: border-box;
141
+
142
+ &:focus {
143
+ border-color: var(--secondary);
144
+ border-width: 2px;
145
+ outline: none;
146
+ padding: calc(0.5rem - 1px);
147
+ }
148
+ }
149
+
150
+ &.compact {
151
+ > label {
152
+ font-size: 1rem;
153
+ line-height: 1.25rem;
154
+ margin-bottom: 2px;
155
+
156
+ @media (--large-screen) {
157
+ font-size: 0.75rem;
158
+ line-height: 1rem;
159
+ }
160
+ }
161
+
162
+ > input {
163
+ font-size: 1.25rem;
164
+ line-height: 1.5rem;
165
+ padding: 0.25rem;
166
+
167
+ &:focus {
168
+ padding: calc(0.25rem - 1px);
169
+ }
170
+
171
+ @media (--large-screen) {
172
+ font-size: 1rem;
173
+ line-height: 1.25rem;
174
+ }
175
+ }
176
+ }
177
+ }
178
+ </style>
@@ -0,0 +1,96 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue';
3
+
4
+ // Props
5
+ const props = defineProps({
6
+ id: {
7
+ type: String,
8
+ required: true,
9
+ },
10
+ message: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ title: {
15
+ type: String,
16
+ default: '',
17
+ },
18
+ });
19
+
20
+ // Computed
21
+ const tooltipId = computed(() => {
22
+ return `tooltip-${props.id}`;
23
+ });
24
+
25
+ // Ref
26
+ const tooltipClass = ref('tooltip');
27
+ </script>
28
+
29
+ <template>
30
+ <div :id="tooltipId" :class="tooltipClass" role="tooltip">
31
+ <p
32
+ v-if="
33
+ props.title !== '' &&
34
+ props.title !== null &&
35
+ props.title !== undefined
36
+ "
37
+ class="tooltip-title"
38
+ >
39
+ {{ props.title }}
40
+ </p>
41
+ <p class="tooltip-message">{{ props.message }}</p>
42
+ </div>
43
+
44
+ <span
45
+ :data-tooltip-target="tooltipId"
46
+ type="tooltip"
47
+ @mouseenter="tooltipClass = 'tooltip show'"
48
+ @mouseleave="tooltipClass = 'tooltip'"
49
+ @focus="tooltipClass = 'tooltip show'"
50
+ @blur="tooltipClass = 'tooltip'"
51
+ @keydown.esc="tooltipClass = 'tooltip'"
52
+ >
53
+ <Info />
54
+ </span>
55
+ </template>
56
+
57
+ <style scoped>
58
+ .tooltip {
59
+ display: none;
60
+ position: absolute;
61
+ z-index: 10;
62
+ padding: 0.75rem 0.25rem;
63
+ background-color: var(--bg-dark);
64
+ border-color: var(--border-muted);
65
+ border-width: var(--border-width);
66
+ border-style: var(--border-style);
67
+ border-radius: var(--border-radius);
68
+ transform: translateY(-100%) translateY(-0.5rem);
69
+ max-width: 75vw;
70
+
71
+ &.show {
72
+ display: inline-block;
73
+ }
74
+
75
+ > .tooltip-title {
76
+ margin: 0 0 0.125rem 0;
77
+ color: var(--text-red);
78
+ }
79
+
80
+ > .tooltip-message {
81
+ font-weight: lighter;
82
+ margin: 0;
83
+ color: var(--text-muted);
84
+ }
85
+
86
+ @media (--large-screen) {
87
+ max-width: 50vw;
88
+ }
89
+ }
90
+
91
+ svg {
92
+ width: 1rem;
93
+ height: 1rem;
94
+ color: var(--text-muted);
95
+ }
96
+ </style>
@@ -0,0 +1,17 @@
1
+ const ObjectTitleCaseEnums = {
2
+ customer: "Customer",
3
+ group: "Group",
4
+ kanban_board: 'Kanban Board',
5
+ kanban_card: "Kanban Card",
6
+ organisation: "Organisation",
7
+ request_for_change: "Request For Change",
8
+ requirement: "Requirement",
9
+ requirement_item: "Requirement Item",
10
+ project: "Project",
11
+ task: "Task",
12
+ user: "User",
13
+ }
14
+
15
+ type ObjectTitleCaseEnums = (typeof ObjectTitleCaseEnums[keyof typeof ObjectTitleCaseEnums])
16
+
17
+ export { ObjectTitleCaseEnums };
@@ -0,0 +1,15 @@
1
+ const ObjectTypeEnums = {
2
+ customer: "customer",
3
+ kanban_board: 'kanban_board',
4
+ kanban_card: "kanban_card",
5
+ organisation: "organisation",
6
+ request_for_change: "request_for_change",
7
+ requirement: "requirement",
8
+ requirement_item: "requirement_item",
9
+ project: "project",
10
+ task: "task",
11
+ }
12
+
13
+ type ObjectTypeEnums = (typeof ObjectTypeEnums)[keyof typeof ObjectTypeEnums]
14
+
15
+ export { ObjectTypeEnums }
@@ -0,0 +1,5 @@
1
+ export interface DocumentItemInterface {
2
+ documentKey: string;
3
+ filename: string;
4
+ type: string;
5
+ }
@@ -0,0 +1,8 @@
1
+ import type {Component} from "vue";
2
+
3
+ export interface DropDownItemsInterface {
4
+ ariaLabel: string;
5
+ icon: Component;
6
+ label: string;
7
+ trigger: string;
8
+ }
@@ -0,0 +1,4 @@
1
+ export interface FolderItemInterface {
2
+ folderId: number;
3
+ folderName: string;
4
+ }
@@ -0,0 +1,10 @@
1
+ import type {Component} from "vue";
2
+
3
+ export interface MenuItemInterface {
4
+ ariaLabel: string;
5
+ destination: string;
6
+ icon: Component;
7
+ route: string;
8
+ routeNew: string;
9
+ title: string;
10
+ }
@@ -0,0 +1,18 @@
1
+ import { test, expect } from '@playwright/test';
2
+
3
+ test('has title', async ({ page }) => {
4
+ await page.goto('https://playwright.dev/');
5
+
6
+ // Expect a title "to contain" a substring.
7
+ await expect(page).toHaveTitle(/Playwright/);
8
+ });
9
+
10
+ test('get started link', async ({ page }) => {
11
+ await page.goto('https://playwright.dev/');
12
+
13
+ // Click the get started link.
14
+ await page.getByRole('link', { name: 'Get started' }).click();
15
+
16
+ // Expects page to have a heading with the name of Installation.
17
+ await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
18
+ });
package/vite.config.ts CHANGED
@@ -2,6 +2,9 @@ import {defineConfig} from 'vite'
2
2
  import vue from '@vitejs/plugin-vue'
3
3
  import postcssNesting from 'postcss-nesting'
4
4
  import {resolve} from 'path'
5
+ import {playwright} from "@vitest/browser-playwright";
6
+ import {configDefaults} from "vitest/config";
7
+ import {fileURLToPath} from "node:url";
5
8
 
6
9
 
7
10
  // https://vite.dev/config/
@@ -10,8 +13,20 @@ export default defineConfig({
10
13
  cssCodeSplit: true,
11
14
  lib: {
12
15
  entry: {
16
+ addObject: resolve(__dirname, 'src/components/add_object/AddObject.vue'),
13
17
  button: resolve(__dirname, 'src/components/button/ButtonComponent.vue'),
14
- style: resolve(__dirname, 'src/styles/main.css'),
18
+ card: resolve(__dirname, 'src/components/card/CardComponent.vue'),
19
+ checkBox: resolve(__dirname, 'src/components/check_box/CheckBox.vue'),
20
+ datetime: resolve(__dirname, 'src/components/datetime/DatetimeComponent.vue'),
21
+ dropDown: resolve(__dirname, 'src/components/drop_down/DropDown.vue'),
22
+ formGroup: resolve(__dirname, 'src/components/form_group/FormGroup.vue'),
23
+ numberInput: resolve(__dirname, 'src/components/number_input/NumberInput.vue'),
24
+ passwordInput: resolve(__dirname, 'src/components/password_input/PasswordInput.vue'),
25
+ renderErrorMessage: resolve(__dirname, 'src/components/render_error_message/RenderErrorMessage.vue'),
26
+ switch: resolve(__dirname, 'src/components/switch/SwitchComponent.vue'),
27
+ textArea: resolve(__dirname, 'src/components/text_area/TextArea.vue'),
28
+ textInput: resolve(__dirname, 'src/components/text_input/TextInput.vue'),
29
+ toolTip: resolve(__dirname, 'src/components/tool_tip/ToolTip.vue'),
15
30
  },
16
31
  name: 'whelk-ui',
17
32
  formats: ['es', 'cjs']
@@ -37,4 +52,28 @@ export default defineConfig({
37
52
  plugins: [
38
53
  vue(),
39
54
  ],
55
+ test: {
56
+ browser: {
57
+ enabled: true,
58
+ provider: playwright(),
59
+ instances: [
60
+ {browser: 'chromium'},
61
+ ],
62
+ },
63
+ coverage: {
64
+ provider: 'v8',
65
+ exclude: [
66
+ 'e2e/**',
67
+ 'src/main.ts'
68
+ ],
69
+ },
70
+ environment: 'jsdom',
71
+ exclude: [
72
+ ...configDefaults.exclude,
73
+ 'e2e/**'
74
+ ],
75
+ root: fileURLToPath(
76
+ new URL('./', import.meta.url)
77
+ ),
78
+ }
40
79
  })