Skip to content

Commit

Permalink
fix: fixes related to migration/compat build
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnixon committed Dec 8, 2023
1 parent bff4456 commit 525bc93
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/components/CvDatePicker/CvDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
data-date-picker-input
role="datepicker"
:data-invalid="isInvalid || null"
:disabled="disabled"
:data-date-picker-input-from="getKind === 'range'"
:disabled="disabled || null"
:data-date-picker-input-from="`${getKind === 'range'}`"
:class="`${carbonPrefix}--date-picker__input`"
:pattern="pattern"
:placeholder="placeholder"
Expand Down Expand Up @@ -87,9 +87,9 @@
type="text"
data-date-picker-input
role="todatepicker"
:data-date-picker-input-to="kind === 'range'"
:data-date-picker-input-to="`${kind === 'range'}`"
:data-invalid="isInvalid || null"
:disabled="disabled"
:disabled="disabled || null"
:class="`${carbonPrefix}--date-picker__input`"
:pattern="pattern"
:placeholder="placeholder"
Expand Down
48 changes: 35 additions & 13 deletions src/components/CvModal/CvModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`cv-modal ${carbonPrefix}--modal`,
{
'is-visible': dataVisible,
[`${carbonPrefix}--modal--danger`]: kind === 'danger',
[`${carbonPrefix}--modal--danger`]: kind === MODAL_KIND_DANGER,
},
]"
tabindex="-1"
Expand Down Expand Up @@ -119,6 +119,15 @@
</template>

<script setup>
import {
MODAL_KIND_DANGER,
MODAL_KIND_PRIMARY,
MODAL_KINDS,
MODAL_SIZE_EXTRA_SMALL,
MODAL_SIZE_LARGE,
MODAL_SIZE_SMALL,
MODAL_SIZES,
} from './index';
import CvButton from '../CvButton/CvButton.vue';
import { carbonPrefix } from '../../global/settings';
import { props as propsCvId, useCvId } from '../../use/cvId';
Expand Down Expand Up @@ -155,7 +164,11 @@ const props = defineProps({
kind: {
type: String,
default: '',
validator: val => ['', 'danger'].includes(val),
validator: val => {
const valid = MODAL_KINDS.includes(val);
if (!valid) console.warn('valid kinds:', MODAL_KINDS);
return valid;
},
},
/**
* boolean value if true the component user is expected to close the modal via visible property.
Expand Down Expand Up @@ -187,8 +200,11 @@ const props = defineProps({
*/
size: {
type: String,
validator: val =>
['', 'xs', 'sm', 'small', 'md', 'large', 'lg'].includes(val),
validator: val => {
const valid = MODAL_SIZES.includes(val);
if (!valid) console.warn('valid sizes:', MODAL_SIZES);
return valid;
},
default: '',
},
/**
Expand Down Expand Up @@ -333,22 +349,22 @@ const dialogAttrs = computed(() => {
return attrs;
});
const primaryKind = computed(() => {
if (props.kind === 'danger') {
return 'danger';
if (props.kind === MODAL_KIND_DANGER) {
return MODAL_KIND_DANGER;
} else {
return 'primary';
return MODAL_KIND_PRIMARY;
}
});
const internalSize = computed(() => {
switch (props.size) {
case 'xs':
return 'xs';
case 'sm':
case MODAL_SIZE_EXTRA_SMALL:
return MODAL_SIZE_EXTRA_SMALL;
case MODAL_SIZE_SMALL:
case 'small':
return 'sm';
case 'lg':
return MODAL_SIZE_SMALL;
case MODAL_SIZE_LARGE:
case 'large':
return 'lg';
return MODAL_SIZE_LARGE;
default:
return '';
}
Expand Down Expand Up @@ -398,4 +414,10 @@ function onOtherBtnClick(ev) {
onBeforeUnmount(() => {
if (dataVisible.value) hide();
});
// exposing methods
defineExpose({
show,
hide,
});
</script>
5 changes: 3 additions & 2 deletions src/components/CvModal/__tests__/CvModal.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import CvModal from '../CvModal.vue';
import { MODAL_KIND_DANGER, MODAL_SIZE_LARGE } from '@/components/CvModal';

describe('CvModal', () => {
it('CvModal - test default and attrs', async () => {
Expand Down Expand Up @@ -86,9 +87,9 @@ describe('CvModal', () => {

await result.rerender({
visible: true,
kind: 'danger',
kind: MODAL_KIND_DANGER,
primaryButtonDisabled: true,
size: 'lg',
size: MODAL_SIZE_LARGE,
hasFormContent: true,
});

Expand Down
30 changes: 29 additions & 1 deletion src/components/CvModal/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
import CvModal from './CvModal.vue';
export { CvModal };

const MODAL_SIZE_EXTRA_SMALL = 'xs';
const MODAL_SIZE_SMALL = 'sm';
const MODAL_SIZE_MEDIUM = 'md';
const MODAL_SIZE_LARGE = 'lg';
const MODAL_SIZES = [
'',
MODAL_SIZE_EXTRA_SMALL,
MODAL_SIZE_SMALL,
'small',
MODAL_SIZE_MEDIUM,
'medium',
'large',
MODAL_SIZE_LARGE,
];
const MODAL_KIND_PRIMARY = 'primary';
const MODAL_KIND_DANGER = 'danger';
const MODAL_KINDS = ['', MODAL_KIND_PRIMARY, MODAL_KIND_DANGER];

export {
CvModal,
MODAL_SIZES,
MODAL_SIZE_EXTRA_SMALL,
MODAL_SIZE_SMALL,
MODAL_SIZE_LARGE,
MODAL_KINDS,
MODAL_KIND_PRIMARY,
MODAL_KIND_DANGER,
};
export default CvModal;
4 changes: 2 additions & 2 deletions src/components/CvMultiSelect/CvMultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ onUpdated(checkSlots);
onMounted(updateOptions);
onMounted(updateSelectedItems);
watch(() => props.modelValue, updateSelectedItems);
watch(() => props.options, updateOptions);
watch(() => props.modelValue, updateSelectedItems, { deep: true });
watch(() => props.options, updateOptions, { deep: true });
watch(() => props.selectionFeedback, updateOptions);
const highlighted = computed({
Expand Down
2 changes: 1 addition & 1 deletion src/components/CvSearch/CvSearch.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<component
:is="formItem ? 'div' : CvEmpty"
:class="`cv-search ${carbonPrefix}--form-item`"
:class="[`cv-search`, `${carbonPrefix}--form-item`, $attrs.class]"
>
<div
ref="elSearch"
Expand Down
4 changes: 2 additions & 2 deletions src/components/CvTabs/CvTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
role="tab"
:aria-controls="tab.uid"
:aria-disabled="disabledTabs.has(tab.uid) || null"
:aria-selected="selectedId === tab.uid"
:aria-selected="`${selectedId === tab.uid}`"
:tabindex="selectedId === tab.uid ? 0 : -1"
type="button"
@click="onTabClick(tab.uid)"
Expand Down Expand Up @@ -187,7 +187,7 @@ function maybeSelectFirstTab() {
if (index > -1) selectedId.value = tabs.value[index].uid;
}
onMounted(maybeSelectFirstTab);
watch(tabs, maybeSelectFirstTab);
watch(tabs, maybeSelectFirstTab, { deep: true });
watch(selectedId, () => {
nextTick(() => {
doTabClick(selectedId.value);
Expand Down

0 comments on commit 525bc93

Please sign in to comment.