मुख्य सामग्री पर जाएं
बटन·मुफ़्त

एसिंक बटन (Vue)

Vue 3 बटन जो एक एसिंक काम चलाता है, इंतज़ार के दौरान स्पिनर दिखाता है और काम पूरा होने तक अतिरिक्त टैप अनदेखे करता है। यह done या error भेजता है, ताकि आगे क्या दिखाना है यह आप तय करें। TypeScript, कोई लाइब्रेरी नहीं।

मुफ़्त में इंस्टॉल करें।

अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।

प्रीव्यू

AsyncButton.vue · 108 लाइनें
<!--
  A button for Vue 3 that runs an async action and blocks double taps while it waits.
  While `action` runs it shows a spinner and `pendingLabel`, sets aria-busy and ignores new
  clicks. If the promise rejects, the button comes back and emits `error`.

    <AsyncButton :action="save" pending-label="Saving…" @error="showError">Save</AsyncButton>

  Colours: --button-bg and --button-text (white text on near-black by default).
-->
<script setup lang="ts">
import { ref } from 'vue';

const props = withDefaults(
  defineProps<{
    action: () => Promise<unknown>;
    pendingLabel?: string;
    disabled?: boolean;
  }>(),
  { pendingLabel: 'Working…', disabled: false },
);

const emit = defineEmits<{ done: []; error: [reason: unknown] }>();

const running = ref(false);

async function run() {
  if (running.value || props.disabled) return;
  running.value = true;
  try {
    await props.action();
    emit('done');
  } catch (reason) {
    emit('error', reason);
  } finally {
    running.value = false;
  }
}
</script>

<template>
  <button
    type="button"
    class="async-button"
    :disabled="disabled"
    :aria-disabled="running || undefined"
    :aria-busy="running || undefined"
    @click="run"
  >
    <span v-if="running" class="spinner" aria-hidden="true"></span>
    <span>
      <template v-if="running">{{ pendingLabel }}</template>
      <slot v-else>Continue</slot>
    </span>
  </button>
</template>

<style scoped>
.async-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.55rem 1.1rem;
  font: 600 1rem system-ui, sans-serif;
  color: var(--button-text, #ffffff);
  background: var(--button-bg, #1d1f23);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.async-button[aria-busy='true'] {
  cursor: progress;
}

.async-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;

यह प्रीव्यू छोटा किया गया है। पूरा कंटेंट इंस्टॉल करने पर मिलेगा।

1.0.0 में बदलाव

पहला संस्करण।

संबंधित

बटन (React + Tailwind)मुफ़्तबटनTypeScript बटन, जिसमें प्राइमरी और सेकेंडरी स्टाइल, साफ़ दिखने वाली फ़ोकस रिंग और एक लोडिंग स्पिनर है जो aria-busy भी सेट करता है। सेकेंडरी स्टाइल में डार्क मोड के रंग हैं।बटन सेट (HTML + CSS)मुफ़्तबटनसादे CSS में प्राइमरी, सेकेंडरी, डेंजर और शांत बटन, साथ में डिसेबल और लोडिंग स्टेट। हर बटन कम से कम 44 × 44 px का है और कीबोर्ड से पहुँचने पर फ़ोकस रिंग दिखाता है। डार्क मोड में रंग बदल जाते हैं और कंट्रास्ट बना रहता है।प्राइमरी बटन (Compose)मुफ़्तबटनMaterial 3 बटन जो टैप करने पर हल्का-सा वाइब्रेट करता है। loading = true करने पर यह स्पिनर दिखाता है और अनुरोध चलने तक टैप को अनदेखा करता है।कॉपी बटन (React)मुफ़्तबटनReact और TypeScript का बटन जो किसी टेक्स्ट को क्लिपबोर्ड पर कॉपी करता है। दो सेकंड तक लेबल "Copied" दिखाता है और एक छिपी स्टेटस लाइन स्क्रीन रीडर को बताती है। किसी CSS फ़्रेमवर्क की ज़रूरत नहीं, और सादे http पर चलने वाले पेज पर यह पुराना कॉपी कमांड इस्तेमाल करता है।टॉगल स्विच (Svelte)मुफ़्तबटनSvelte 5 के लिए ऑन/ऑफ़ स्विच, जो role switch वाले बटन से बना है, इसलिए Space, Enter और स्क्रीन रीडर काम करते हैं। checked बाइंड करें या onchange दें। इसमें वैकल्पिक दूसरी लाइन, बंद (disabled) स्थिति और CSS वैरिएबल से रंग हैं।साइन-अप फ़ॉर्म (Vue)मुफ़्तपेजTypeScript में Vue 3 सिंगल-फ़ाइल कंपोनेंट के रूप में साइन-अप फ़ॉर्म, जिसमें नाम, ईमेल और पासवर्ड हैं। किसी फ़ील्ड से हटने पर यह बताता है कि क्या गलत है, और स्क्रीन रीडर भी वही संदेश सुनाते हैं। कोई लाइब्रेरी नहीं; रंग CSS वैरिएबल से आते हैं।