Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: another time for the button children #120

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading