Skip to content

Commit b7f8678

Browse files
authored
feat 0.17/4 (#491)
## Chore: * chore: increment version ## Fix: * fix(button): handle auto and % width values on loading * fix(button): avoid setting width to auto * This could caused issues when turning button back from loading ## Feature: * feat: made error message more helpful ## Testing * test: updated helper test * test: updated button tests
1 parent 20a91ec commit b7f8678

File tree

7 files changed

+27
-11
lines changed

7 files changed

+27
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@karnama/vueish",
3-
"version": "0.17.3",
3+
"version": "0.17.4",
44
"files": [
55
"dist",
66
"types"

src/components/button/UIButton.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('UIButton', () => {
107107
}
108108
});
109109

110-
expect(wrapper.find('.loader').isVisible()).toBe(true);
110+
expect(wrapper.find('.ui-button-loader').isVisible()).toBe(true);
111111
expect(wrapper.find('.label').exists()).toBe(false);
112112
});
113113

src/components/button/UIButton.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:style="styles"
66
class="ui-button rounded font-bold text-sm m-0 focus:outline-none ring-0
77
disabled:cursor-not-allowed disabled:shadow-none">
8-
<span v-if="loading" class="loader">
8+
<span v-if="loading" class="ui-button-loader">
99
<slot name="loader">
1010
<UISpinnerLoader inherit-color
1111
class="mx-auto"
@@ -313,14 +313,28 @@ export default defineComponent({
313313
const styles: Partial<CSSStyleDeclaration> = {};
314314
315315
watch(() => props.loading, newVal => {
316+
const computedStyle = getComputedStyle(instance.proxy!.$el as HTMLButtonElement);
317+
318+
if (computedStyle.width === 'auto' || computedStyle.width.endsWith('%')) {
319+
return;
320+
}
321+
316322
// while loading sizing props might change but on
317323
// next loading it will set to the correct width
318324
if (newVal && !instance.slots.loader) {
319-
const computedStyle = getComputedStyle(instance.proxy!.$el as HTMLButtonElement);
320-
const minWidthRequirement = (props.small ? 20 : 25) + getPxValue(computedStyle.paddingInline) * 2;
325+
const paddingInline = computedStyle.paddingInline === 'auto' ||
326+
computedStyle.paddingInline.endsWith('%')
327+
? 0
328+
: getPxValue(computedStyle.paddingInline);
321329
322-
styles.width = getPxValue(computedStyle.width) < minWidthRequirement ? 'auto' : computedStyle.width;
330+
const minWidthRequirement = (props.small ? 20 : 25) + paddingInline * 2;
331+
332+
if (getPxValue(computedStyle.width) < minWidthRequirement) return;
333+
334+
styles.width = computedStyle.width;
323335
} else {
336+
if (!styles.width) return;
337+
324338
styles.width = 'auto';
325339
}
326340
});

src/components/button/__snapshots__/UIButton.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`UIButton should display the loading correctly 1`] = `
66
type="button"
77
>
88
<span
9-
class="loader"
9+
class="ui-button-loader"
1010
>
1111
1212
<transition-stub>

src/composables/style/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export const getPxValue = (value: string | number): number => {
2828
parseFloat(globalThis?.window.getComputedStyle(globalThis?.document.documentElement).fontSize);
2929
}
3030

31-
throw new TypeError('Unexpected argument given.');
31+
throw new TypeError('Unexpected argument given. Expected a number, px/vh/vw/rem value, got: ' + value);
3232
};

src/composables/style/style.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ describe('style', () => {
2828
});
2929

3030
it('should throw an error on invalid argument', () => {
31-
expect(() => getPxValue('something')).toThrow(new TypeError('Unexpected argument given.'));
31+
expect(() => getPxValue('something'))
32+
.toThrow(new TypeError('Unexpected argument given. Expected a number, px/vh/vw/rem value, got: '
33+
+ 'something'));
3234
});
3335

3436
it('should correctly convert vw to px', () => {

0 commit comments

Comments
 (0)