ソースを参照

docs: add drag international en-us

Drjnigfubo 3 年 前
コミット
dea7285d39
2 ファイル変更338 行追加16 行削除
  1. 48 16
      src/packages/__VUE/toast/demo.vue
  2. 290 0
      src/packages/__VUE/toast/doc.en-US.md

+ 48 - 16
src/packages/__VUE/toast/demo.vue

@@ -1,25 +1,56 @@
 <template>
   <div class="demo">
-    <h2>基本用法</h2>
-    <nut-cell title="Text 文字提示" is-link @click="textToast('网络失败,请稍后再试~')"></nut-cell>
-    <nut-cell title="Title 标题展示" is-link @click="titleToast('网络失败,请稍后再试~')"></nut-cell>
-    <nut-cell title="Success 成功提示" is-link @click="successToast('成功提示')"></nut-cell>
-    <nut-cell title="Error 失败提示" is-link @click="errorToast('失败提示')"></nut-cell>
-    <nut-cell title="Warning 警告提示" is-link @click="warningToast('警告提示')"></nut-cell>
-    <nut-cell title="Loading 加载提示" is-link @click="loadingToast('加载中')"></nut-cell>
-    <h2>Toast不消失</h2>
-    <nut-cell title="Toast 文字提示不消失" is-link @click="NoToast('Toast不消失~')"></nut-cell>
-    <h2>Toast自定义距离底部高度</h2>
-    <nut-cell title="Toast 自定义底部高度" is-link @click="BottomToast('自定义距离~')"></nut-cell>
-    <h2>Loading带透明遮罩</h2>
-    <nut-cell title="带文案+带透明遮罩+自动消失" is-link @click="NoLoading('加载中~')"></nut-cell>
+    <h2>{{ translate('basic') }}</h2>
+    <nut-cell :title="translate('toastText')" is-link @click="textToast(translate('toastText'))"></nut-cell>
+    <nut-cell :title="translate('toastTitle')" is-link @click="titleToast(translate('toastText'))"></nut-cell>
+    <nut-cell :title="translate('toastSuccess')" is-link @click="successToast(translate('toastSuccess'))"></nut-cell>
+    <nut-cell :title="translate('toastError')" is-link @click="errorToast(translate('toastError'))"></nut-cell>
+    <nut-cell :title="translate('toastWarning')" is-link @click="warningToast(translate('toastWarning'))"></nut-cell>
+    <nut-cell :title="translate('toastLoading')" is-link @click="loadingToast(translate('toastLoading'))"></nut-cell>
+    <h2>{{ translate('toastAll') }}</h2>
+    <nut-cell :title="translate('toastAll')" is-link @click="NoToast(translate('toastAll'))"></nut-cell>
+    <h2>{{ translate('toastBottom') }}</h2>
+    <nut-cell :title="translate('toastBottom')" is-link @click="BottomToast(translate('toastBottom'))"></nut-cell>
+    <h2>{{ translate('toastTransparent') }}</h2>
+    <nut-cell
+      :title="translate('toastTransparent')"
+      is-link
+      @click="NoLoading(translate('toastTransparent'))"
+    ></nut-cell>
   </div>
 </template>
 
 <script lang="ts">
 import { createComponent } from '@/packages/utils/create';
-const { createDemo } = createComponent('toast');
+const { createDemo, translate } = createComponent('toast');
 import { Toast } from '@/packages/nutui.vue';
+import { useTranslate } from '@/sites/assets/util/useTranslate';
+useTranslate({
+  'zh-CN': {
+    basic: '基本用法',
+    toastText: '文字提示',
+    toastTitle: '标题展示',
+    toastSuccess: '成功提示',
+    toastError: '错误提示',
+    toastWarning: '警告提示',
+    toastLoading: '加载提示',
+    toastAll: 'Toast 不消失',
+    toastBottom: '自定义底部高度',
+    toastTransparent: '加载状态透明遮罩'
+  },
+  'en-US': {
+    basic: 'Basic Usage',
+    toastText: 'Text Message',
+    toastTitle: 'Title',
+    toastSuccess: 'Success',
+    toastError: 'Error',
+    toastWarning: 'Warning',
+    toastLoading: 'Loading',
+    toastAll: 'Not Disappear',
+    toastBottom: 'Custom Bottom Height',
+    toastTransparent: 'Loading Transparent Cover'
+  }
+});
 export default createDemo({
   setup() {
     const textToast = (msg: string) => {
@@ -27,7 +58,7 @@ export default createDemo({
     };
     const titleToast = (msg: string) => {
       Toast.text(msg, {
-        title: '标题文字'
+        title: translate('toastTitle')
       });
     };
     const successToast = (msg: string) => {
@@ -67,7 +98,8 @@ export default createDemo({
       loadingToast,
       NoToast,
       NoLoading,
-      BottomToast
+      BottomToast,
+      translate
     };
   }
 });

+ 290 - 0
src/packages/__VUE/toast/doc.en-US.md

@@ -0,0 +1,290 @@
+# Toast
+
+### Intro
+
+for light tips.
+
+### Install
+
+``` javascript
+import { createApp } from 'vue';
+import { Toast } from '@nutui/nutui';
+
+const app = createApp();
+app.use(Toast);
+```
+
+## Usage
+
+#### Global Usage
+:::demo
+``` html
+<template>
+</template>
+<script>
+import { getCurrentInstance } from 'vue';
+export default {
+  setup() {
+   const { proxy } = getCurrentInstance();
+    proxy.$toast.text('global usage');
+    return {};
+  }
+}
+</script>
+```
+:::
+
+#### Text
+:::demo
+```html
+<template>
+  <nut-cell title="Text" is-link @click="textToast('text message~')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.text(msg);
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+#### Title
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Title" is-link @click="textToast('title message~')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.text(msg, {
+        title: 'title'
+      });
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+#### Success
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Success" is-link @click="textToast('Success')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+       Toast.success(msg);
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+#### Fail
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Fail" is-link @click="textToast('Fail')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.fail(msg);
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+#### Warn
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Warn" is-link @click="textToast('Warn')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.warn(msg);
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+#### Loading
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Loading" is-link @click="textToast('Loading')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.loading(msg);
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+#### Not Disappear
+
+:::demo
+```html
+<template>
+  <nut-cell title="Toast Not Disappear" is-link @click="textToast('Toast Not Disappear')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+     Toast.text(msg, {
+        duration: 0
+      });
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+#### Custom Bottom Height
+
+:::demo
+```html
+<template>
+  <nut-cell title="Custom Bottom Height" is-link @click="textToast('Custom Bottom Height')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+      Toast.text(msg, {
+        center: false,
+        bottom: '10%'
+      });
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+#### Loading with transparent cover
+:::demo
+```html
+<template>
+  <nut-cell title="Loading with transparent cover" is-link @click="textToast('Loading')"></nut-cell>
+</template>
+<script>
+import { Toast } from '@nutui/nutui';
+export default {
+  setup() {
+     const textToast = (msg) => {
+       Toast.loading(msg, {
+        cover: true
+      });
+    };
+    return {
+      textToast,
+    };
+  }
+}
+</script>
+```
+:::
+
+
+####  Support import and use in JS modules
+``` javascript
+import { Toast } from "@nutui/nutui";
+Toast.text('use in js module');
+// Return the instance, you can manually call the hide method in the instance to close the prompt
+const toast = Toast.loading('use in js module');
+toast.hide();
+```
+
+
+### API
+| Methods                    | Description              | Attribute          | Return value     |
+| ------------------------- | ----------------------------------------------------------------------- | --------------- | ---------- |
+| Toast.text                | Show text toast   |  message| options | toast instance(message support incoming HTML) |
+| Toast.success             | Show success toast     | message| options| toast instance |
+| Toast.fail                | Show fail toast   | message| options| toast instance|
+| Toast.warn                | Show warn toast    | message| options | toast instance |
+| Toast.hide                | Close toast     | clearAll: boolean   | void       |
+| Toast.loading             | Show loading toast      | message| options | toast instance |
+
+## Options
+
+| 字段                | 说明                                                                          | 类型          | 默认值                        |
+| ------------------- | ----------------------------------------------------------------------------- | ------------- | ----------------------------- |
+| id                  | Identifier, share one instance at the same time, default to multiple instances| String/Number | -            |
+| duration            | Toast duration(ms), won't disappear if value is 0      | Number        | 2000                          |
+| title            | title     | String        |           -             |
+| center  | Whether to display in the middle of the page (display at the bottom when false) | Boolean| true                          |
+| bottom | The distance from the bottom of the page (px or %), which takes effect when option.center is false | String| 30px       |
+| textAlignCenter     | Whether the multi-line copy is centered           | Boolean       | true                          |
+| bgColor             | background color (transparency) | String        | rgba(0, 0, 0, 0.8)      |
+| customClass         |   Custom Class          | String        |          -                   |
+| icon                | Custom Icon        | String        |         -                   |
+| iconSize    | Custom iconSize      | String        | 20                           |
+| size        | Text Size **small**/**base**/**large**          | String        | base      |
+| cover      | Whether to show the mask layer     | Boolean       | false |
+| cover-color   | Cover Color   | String        | rgba(0,0,0,0)             |
+| loadingRotate  | Whether the loading icon is rotated, only valid for the loading type  | Boolean | true                          |
+| close             | Callback function after close                   | function      | null                          |
+| close-on-click-overlay | 	Whether to close when overlay is clicked                  | Boolean       | false                         |
+| custom-class          | Custom Class                      | String       |               -          |
+