Skip to content

Commit

Permalink
fix: another time for the button children (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagraber authored Nov 12, 2024
1 parent d35efc6 commit 1f293f5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
21 changes: 16 additions & 5 deletions src/components/Button/PdapButton.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<template>
<button :class="classes">
<TransitionGroup mode="out-in">
<slot v-if="!isLoading" />
<slot v-if="isLoading && $slots.loading" name="loading" />
<Spinner v-if="isLoading && !$slots.loading" :show="isLoading" />
</TransitionGroup>
<Transition mode="out-in">
<component
:is="
isLoading && $slots.loading
? $slots.loading
: isLoading
? Spinner
: $slots.default
"
v-bind="isLoading ? loadingProps : undefined"
/>
</Transition>
</button>
</template>

Expand All @@ -22,6 +29,10 @@ const props = withDefaults(defineProps<PdapButtonProps>(), {
isLoading: false,
});
const loadingProps = {
show: props.isLoading,
};
// CSS class map
const classes = reactive({
'pdap-button': true,
Expand Down
5 changes: 1 addition & 4 deletions src/components/Button/__snapshots__/button.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

exports[`Renders button component > Renders a button 1`] = `
<button class="pdap-button pdap-button-primary">
<transition-group-stub appear="false" css="true" mode="out-in" persisted="false">Button Content
<!--v-if-->
<!--v-if-->
</transition-group-stub>
<transition-stub appear="false" css="true" mode="out-in" persisted="false">Button Content</transition-stub>
</button>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ exports[`QuickSearchForm component > Renders a QuickSearchForm 1`] = `
</label>
</div>
<button class="pdap-button pdap-button-primary flex-grow-0 flex-shrink-0 basis-full max-w-[unset] mt-4" type="submit">
<transition-group-stub appear="false" css="true" mode="out-in" persisted="false">Search Data Sources
<!--v-if-->
<!--v-if-->
</transition-group-stub>
<transition-stub appear="false" css="true" mode="out-in" persisted="false">Search Data Sources</transition-stub>
</button>
</form>
<p class="max-w-[unset] text-med"> For example, you could search for <a> stops in Pittsburgh </a> or <a> complaints everywhere </a> . </p>
Expand Down
11 changes: 10 additions & 1 deletion src/demo/pages/FormV2Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
:rows="5"
/>

<Button type="submit">Submit</Button>
<Button :is-loading="mockLoading" type="submit">Submit</Button>
</FormV2>
</main>
</template>
Expand All @@ -73,6 +73,15 @@ import { InputCheckbox } from '../../components/InputCheckbox';
import { InputPassword } from '../../components/InputPassword';
import { InputSelect } from '../../components/InputSelect';
import PdapInputTextArea from '../../components/InputTextArea/PdapInputTextArea.vue';
import { onMounted, ref } from 'vue';
const mockLoading = ref(true);
onMounted(() => {
setTimeout(() => {
mockLoading.value = false;
}, 5000);
});
const INPUT_CHECKBOX_NAME = 'ice-cream';
const INPUT_TEXT_PLACEHOLDER = 'Paul';
Expand Down

0 comments on commit 1f293f5

Please # to comment.