@teammodlr/ui-kit 3.0.0-beta.33 → 3.0.0-beta.36

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 (39) hide show
  1. package/lib/components/clearbutton/ClearButton.vue.d.ts +7 -0
  2. package/lib/components/clearbutton/style/ClearButton.css.d.ts +2 -0
  3. package/lib/components/clearbutton/style/index.d.ts +1 -0
  4. package/lib/components/hovercard/HoverCard.vue.d.ts +122 -0
  5. package/lib/components/hovercard/style/HoverCard.css.d.ts +3 -0
  6. package/lib/components/hovercard/style/index.d.ts +1 -0
  7. package/lib/components/index.d.ts +1 -0
  8. package/lib/components/input/Input.vue.d.ts +15 -0
  9. package/lib/components/input/style/Input.css.d.ts +4 -0
  10. package/lib/components/select/Select.vue.d.ts +12 -0
  11. package/lib/components/select/style/Select.css.d.ts +2 -1
  12. package/lib/components/textarea/Textarea.vue.d.ts +11 -0
  13. package/lib/components/textarea/style/Textarea.css.d.ts +2 -0
  14. package/lib/index.cjs.js +3 -3
  15. package/lib/index.es.js +4853 -4079
  16. package/lib/style.css +1 -1
  17. package/package.json +1 -1
  18. package/src/components/clearbutton/ClearButton.vue +39 -0
  19. package/src/components/clearbutton/style/ClearButton.css.ts +37 -0
  20. package/src/components/clearbutton/style/index.ts +1 -0
  21. package/src/components/hovercard/HoverCard.vue +163 -0
  22. package/src/components/hovercard/style/HoverCard.css.ts +175 -0
  23. package/src/components/hovercard/style/index.ts +1 -0
  24. package/src/components/index.ts +1 -1
  25. package/src/components/input/Input.vue +51 -3
  26. package/src/components/input/examples/clearable.vue +18 -0
  27. package/src/components/input/examples/index.stories.ts +3 -1
  28. package/src/components/input/examples/index.ts +1 -0
  29. package/src/components/input/style/Input.css.ts +20 -0
  30. package/src/components/select/Select.vue +31 -1
  31. package/src/components/select/examples/clearable.vue +18 -0
  32. package/src/components/select/examples/index.stories.ts +2 -1
  33. package/src/components/select/examples/index.ts +1 -0
  34. package/src/components/select/style/Select.css.ts +9 -6
  35. package/src/components/textarea/Textarea.vue +39 -3
  36. package/src/components/textarea/examples/clearable.vue +16 -0
  37. package/src/components/textarea/examples/index.stories.ts +2 -1
  38. package/src/components/textarea/examples/index.ts +1 -0
  39. package/src/components/textarea/style/Textarea.css.ts +11 -0
@@ -17,12 +17,14 @@
17
17
  :value="textareaValue"
18
18
  :readonly="readonly"
19
19
  v-on="inputListeners"
20
+ @input="onNativeInput"
20
21
  :class="inputComputedClasses"
21
22
  v-bind="$attrs"
22
23
  :disabled="disabled || loading"
23
24
  :aria-disabled="disabled ? 'true' : 'false'"
24
25
  :aria-labelledby="`${id}-label`"
25
26
  />
27
+ <MClearButton v-if="showClear" :class="style.clear" @clear="onClear" />
26
28
  </div>
27
29
  <div v-if="inputError" :class="style.errorMessage">
28
30
  {{ inputError }}
@@ -37,14 +39,17 @@ import {
37
39
  defineComponent,
38
40
  ref,
39
41
  computed,
40
- toRef
42
+ toRef,
43
+ watch
41
44
  } from "vue";
42
45
  import { useInput } from "../../composables/useInput";
43
46
  import { useInteractive } from "../../composables/useInteractive";
47
+ import MClearButton from '../clearbutton/ClearButton.vue';
44
48
  import * as style from './style';
45
49
 
46
50
  export default defineComponent({
47
51
  name: 'MTextArea',
52
+ components: { MClearButton },
48
53
  props: {
49
54
  ...useInput.props(),
50
55
  ...useInteractive.props(),
@@ -87,8 +92,12 @@ export default defineComponent({
87
92
  type: Number,
88
93
  default: 64
89
94
  },
95
+ clearable: {
96
+ type: Boolean,
97
+ default: false
98
+ },
90
99
  },
91
- emits: useInput.emits(),
100
+ emits: [...useInput.emits(), 'clear'],
92
101
  setup(props, { emit, expose }) {
93
102
  const element = ref<HTMLTextAreaElement | null>(null);
94
103
  const { focus, blur } = useInteractive(element);
@@ -136,6 +145,7 @@ export default defineComponent({
136
145
  [style.block]: props.block,
137
146
  [style.disabled]: disabled.value || loading.value,
138
147
  [style.error]: inputError.value,
148
+ [style.hasClear]: props.clearable,
139
149
  }
140
150
  ];
141
151
  });
@@ -144,12 +154,36 @@ export default defineComponent({
144
154
  return formError.value || props.error;
145
155
  });
146
156
 
157
+ // Tracks typed text so clearable works without v-model
158
+ const internalValue = ref('');
159
+ watch(() => props.modelValue, value => {
160
+ internalValue.value = value == null ? '' : String(value);
161
+ }, { immediate: true });
162
+
147
163
  const textareaValue = computed(() => {
148
- return props.modelValue == null ? '' : String(props.modelValue);
164
+ if (props.modelValue !== undefined) {
165
+ return props.modelValue == null ? '' : String(props.modelValue);
166
+ }
167
+ return internalValue.value;
168
+ });
169
+
170
+ const onNativeInput = (event: Event) => {
171
+ internalValue.value = (event.target as HTMLTextAreaElement).value;
172
+ };
173
+
174
+ const showClear = computed(() => {
175
+ return props.clearable
176
+ && !disabled.value
177
+ && !loading.value
178
+ && !readonly.value
179
+ && textareaValue.value !== '';
149
180
  });
150
181
 
151
182
  const onClear = () => {
183
+ internalValue.value = '';
152
184
  emit('update:modelValue', '');
185
+ emit('clear');
186
+ focus();
153
187
  };
154
188
 
155
189
  expose({
@@ -171,6 +205,8 @@ export default defineComponent({
171
205
  textareaValue,
172
206
  inputError,
173
207
  style,
208
+ showClear,
209
+ onNativeInput,
174
210
 
175
211
  onClear,
176
212
  validate,
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <MTextArea
3
+ v-model="value"
4
+ label="Some Text"
5
+ name="text"
6
+ placeholder="Some text placeholder"
7
+ :height="128"
8
+ clearable
9
+ />
10
+ </template>
11
+
12
+ <script lang="ts" setup>
13
+ import { ref } from 'vue';
14
+
15
+ const value = ref('Clear me');
16
+ </script>
@@ -1,5 +1,5 @@
1
1
  import MTextarea from '../Textarea.vue';
2
- import { MTextareaBasic } from './index';
2
+ import { MTextareaBasic, MTextareaClearable } from './index';
3
3
 
4
4
  import { createStory, sizeArgType } from '../../../__storybook__';
5
5
 
@@ -12,3 +12,4 @@ export default {
12
12
  };
13
13
 
14
14
  export const Basic = createStory(MTextareaBasic);
15
+ export const Clearable = createStory(MTextareaClearable);
@@ -1 +1,2 @@
1
1
  export { default as MTextareaBasic } from './basic.vue';
2
+ export { default as MTextareaClearable } from './clearable.vue';
@@ -144,6 +144,17 @@ export const disabled = style({
144
144
  }
145
145
  });
146
146
 
147
+ export const hasClear = style({
148
+ paddingRight: '1.75rem'
149
+ });
150
+
151
+ export const clear = style({
152
+ position: 'absolute',
153
+ zIndex: 1,
154
+ top: themeVars.space[1],
155
+ right: themeVars.space[1]
156
+ });
157
+
147
158
  export const label = style({
148
159
  fontWeight: '500',
149
160
  display: 'inline-block',