Skip to content

Commit

Permalink
feat 0.17/4 (#491)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
nandi95 authored Jul 26, 2022
1 parent 20a91ec commit b7f8678
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@karnama/vueish",
"version": "0.17.3",
"version": "0.17.4",
"files": [
"dist",
"types"
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/UIButton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('UIButton', () => {
}
});

expect(wrapper.find('.loader').isVisible()).toBe(true);
expect(wrapper.find('.ui-button-loader').isVisible()).toBe(true);
expect(wrapper.find('.label').exists()).toBe(false);
});

Expand Down
22 changes: 18 additions & 4 deletions src/components/button/UIButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:style="styles"
class="ui-button rounded font-bold text-sm m-0 focus:outline-none ring-0
disabled:cursor-not-allowed disabled:shadow-none">
<span v-if="loading" class="loader">
<span v-if="loading" class="ui-button-loader">
<slot name="loader">
<UISpinnerLoader inherit-color
class="mx-auto"
Expand Down Expand Up @@ -313,14 +313,28 @@ export default defineComponent({
const styles: Partial<CSSStyleDeclaration> = {};
watch(() => props.loading, newVal => {
const computedStyle = getComputedStyle(instance.proxy!.$el as HTMLButtonElement);
if (computedStyle.width === 'auto' || computedStyle.width.endsWith('%')) {
return;
}
// while loading sizing props might change but on
// next loading it will set to the correct width
if (newVal && !instance.slots.loader) {
const computedStyle = getComputedStyle(instance.proxy!.$el as HTMLButtonElement);
const minWidthRequirement = (props.small ? 20 : 25) + getPxValue(computedStyle.paddingInline) * 2;
const paddingInline = computedStyle.paddingInline === 'auto' ||
computedStyle.paddingInline.endsWith('%')
? 0
: getPxValue(computedStyle.paddingInline);
styles.width = getPxValue(computedStyle.width) < minWidthRequirement ? 'auto' : computedStyle.width;
const minWidthRequirement = (props.small ? 20 : 25) + paddingInline * 2;
if (getPxValue(computedStyle.width) < minWidthRequirement) return;
styles.width = computedStyle.width;
} else {
if (!styles.width) return;
styles.width = 'auto';
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/__snapshots__/UIButton.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`UIButton should display the loading correctly 1`] = `
type="button"
>
<span
class="loader"
class="ui-button-loader"
>
<transition-stub>
Expand Down
2 changes: 1 addition & 1 deletion src/composables/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const getPxValue = (value: string | number): number => {
parseFloat(globalThis?.window.getComputedStyle(globalThis?.document.documentElement).fontSize);
}

throw new TypeError('Unexpected argument given.');
throw new TypeError('Unexpected argument given. Expected a number, px/vh/vw/rem value, got: ' + value);
};
4 changes: 3 additions & 1 deletion src/composables/style/style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe('style', () => {
});

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

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

0 comments on commit b7f8678

Please sign in to comment.