### Install Tailwind CSS
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
Install Tailwind CSS version 3. Higher versions are not supported. This command installs Tailwind CSS as a development dependency.
```bash
npm install tailwindcss@3 -D
```
--------------------------------
### Spacing and Sizing Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
Example SCSS utility classes for controlling width, height, margin, padding, top position, and gap. These classes use `rpx` units and are configured in `tailwind.config.js`.
```scss
.w-100 {
width: 100rpx !important;
}
.h-100 {
height: 100rpx !important;
}
.m-100 {
margin: 100rpx !important;
}
.p-100 {
padding: 100rpx !important;
}
.top-100 {
top: 100rpx !important;
}
.gap-100 {
gap: 100rpx !important;
}
// ...
```
--------------------------------
### Picker CSS Variables
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/picker.md
Customize the appearance of the Picker component using CSS variables. This example shows the available variables for theming.
```scss
:root {
--picker-item-height: 44px;
--picker-mask-color: rgba(255, 255, 255, 0.7);
--picker-indicator-color: #000;
--picker-indicator-border: 1px solid #e0e0e0;
--picker-column-width: auto;
}
```
--------------------------------
### Imperative Popup Agent Setup
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/popup.md
Place a `sar-popup-agent` component on the page to manage popups imperatively. You can assign an `id` to the agent to control specific agents when displaying multiple imperative popups.
```vue
```
--------------------------------
### ScrollList CSS Variables
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/scroll-list.md
Provides an example of customizing the ScrollList component's appearance using CSS variables for theming.
```scss
<<< @comp/scroll-list/variables.scss#variables
```
--------------------------------
### Local Theme Customization with CSS Variables
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/guide/theme.md
Customize themes for specific components or sections by applying CSS variables directly to the element or its parent container. This example shows how to change the `--sar-primary` color for a button locally.
```html
button
button
```
--------------------------------
### Creating Request Instances
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/request.md
Shows how to use the `createRequest` factory function to instantiate `Request` objects with different base URLs.
```APIDOC
## Creating Request Instances
Instantiate `Request` objects using the `createRequest` factory function, specifying a `baseURL` for each instance.
### Example Usage
```ts
export const requestV1 = createRequest({
baseURL: 'http://localhost/api-v1',
})
export const requestV2 = createRequest({
baseURL: 'http://localhost/api-v2',
})
```
```
--------------------------------
### getLunarDayName
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/date.md
Gets the Chinese name for a given lunar day.
```APIDOC
## getLunarDayName
### Description
Gets the Chinese name for a lunar day. Example: 初一, 十二, 廿一.
### Signature
```ts
function getLunarDayName(day: number): string
```
```
--------------------------------
### Basic Picker Usage
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/picker.md
Demonstrates the basic usage of the Picker component. Bind the current value using `v-model` and configure options with the `columns` prop.
```vue
```
--------------------------------
### UseSlotMachineReturn
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/lucky-draw.md
Methods and computed properties for controlling the slot machine animation.
```APIDOC
## UseSlotMachineReturn
### Description
Provides methods to control the slot machine animation and computed properties to get its current state.
### Methods
- **play**: `() => void` - Starts the slot machine animation.
- **stop**: `(index?: number[]) => void` - Starts the deceleration animation for specified columns.
- **pause**: `() => void` - Pauses the animation.
- **reset**: `() => void` - Resets the animation to its initial state.
### Computed Properties
- **playing**: `ComputedRef` - Indicates whether the animation is currently running.
- **offset**: `ComputedRef` - The current offset for each column.
```
--------------------------------
### Import PullDownRefresh Component
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/pull-down-refresh.md
Import the PullDownRefresh component from the sard-uniapp library.
```javascript
import PullDownRefresh from 'sard-uniapp/components/pull-down-refresh/pull-down-refresh.vue'
```
--------------------------------
### Basic Usage of PickerPopout
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/picker-popout.md
Demonstrates the basic usage of PickerPopout. Use `v-model` for two-way binding of the current value and `v-model:visible` to control the popout's visibility.
```vue
```
--------------------------------
### Grayscale Scene Color Utilities
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
Adds utility classes for grayscale scene colors, providing adaptable background and text colors for light and dark system themes. These classes use CSS variables for dynamic theming.
```scss
.sbg-body {
background-color: var(--sar-body-bg) !important;
}
.sbg-secondary {
background-color: var(--sar-secondary-bg) !important;
}
.sbg-tertiary {
background-color: var(--sar-tertiary-bg) !important;
}
.sbg-fourth {
background-color: var(--sar-fourth-bg) !important;
}
.sbg-emphasis {
background-color: var(--sar-emphasis-bg) !important;
}
.sbg-active {
background-color: var(--sar-active-bg) !important;
}
.sbg-active-deep {
background-color: var(--sar-active-deep-bg) !important;
}
.stext-body {
color: var(--sar-body-color) !important;
}
.stext-secondary {
color: var(--sar-secondary-color) !important;
}
.stext-tertiary {
color: var(--sar-tertiary-color) !important;
}
.stext-fourth {
color: var(--sar-fourth-color) !important;
}
.stext-emphasis {
color: var(--sar-emphasis-color) !important;
}
```
--------------------------------
### Font Size Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
SCSS utility classes for controlling font size, mapping to Sard Uniapp's CSS variables for xs, sm, base, lg, xl, and 2xl sizes.
```scss
.text-xs {
font-size: var(--sar-text-xs) !important;
}
.text-sm {
font-size: var(--sar-text-sm) !important;
}
.text-base {
font-size: var(--sar-text-base) !important;
}
.text-lg {
font-size: var(--sar-text-lg) !important;
}
.text-xl {
font-size: var(--sar-text-xl) !important;
}
.text-2xl {
font-size: var(--sar-text-2xl) !important;
}
```
--------------------------------
### getDaysBeforeFirstDay
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/date.md
Calculates the number of days from the previous month that need to be displayed before the first day of the current month.
```APIDOC
## getDaysBeforeFirstDay
### Description
Calculates the number of trailing days from the previous month that need to be displayed before the 1st of the current month.
### Signature
```ts
function getDaysBeforeFirstDay(
year: number,
month: number,
weekStartsOn?: number,
): number
```
```
--------------------------------
### Upload File Configuration
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/request.md
Defines the configuration options for the `request.upload` method, including parameters for file uploads, headers, timeouts, and form data.
```ts
request.upload('api/upload', {
/**
* 资源url
*/
url?: string
/**
* 自动加在 `url` 前面,除非 `url` 是一个绝对 URL
*/
baseURL?: string
/**
* 与请求一起发送的 URL 参数
*/
params?: {
[key: string]: any
}
/**
* 获取 uni.uploadFile 返回值,可用于中断请求
*/
getTask?: (task: UniApp.UploadTask, config: RequestConfig) => void
/**
* 设置请求的 header,header 中不能设置 Referer。
*/
header?: any
/**
* 超时时间
*/
timeout?: number
/**
* 需要上传的文件列表。App、H5( 2.6.15+)
*/
files?: UploadFileOptionFiles[]
/**
* 文件类型,image/video/audio,仅支付宝小程序,且必填。
* - image: 图像
* - video: 视频
* - audio: 音频
*/
fileType?: 'image' | 'video' | 'audio'
/**
* 要上传的文件对象。\t仅H5(2.6.15+)支持
*/
file?: File
/**
* 要上传文件资源的路径
*/
filePath?: string
/**
* 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
*/
name?: string
/**
* HTTP 请求中其他额外的 form data
*/
formData?: {
[key: string]: any
}
})
```
--------------------------------
### Theme Color Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
SCSS utility classes for text and background colors, mapping to Sard Uniapp's CSS variables for primary, secondary, success, info, warning, and danger themes.
```scss
.text-primary {
color: var(--sar-primary) !important;
}
.text-secondary {
color: var(--sar-secondary) !important;
}
.text-success {
color: var(--sar-success) !important;
}
.text-info {
color: var(--sar-info) !important;
}
.text-warning {
color: var(--sar-warning) !important;
}
.text-danger {
color: var(--sar-danger) !important;
}
.bg-primary {
background-color: var(--sar-primary) !important;
}
.bg-secondary {
background-color: var(--sar-secondary) !important;
}
.bg-success {
background-color: var(--sar-success) !important;
}
.bg-info {
background-color: var(--sar-info) !important;
}
.bg-warning {
background-color: var(--sar-warning) !important;
}
.bg-danger {
background-color: var(--sar-danger) !important;
}
// ...
```
--------------------------------
### Generic Request Factory Function
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/request.md
Demonstrates how to create a generic `Request` factory function that handles adding tokens, error status codes, error messages, and retries. This function can be used to create pre-configured request instances.
```APIDOC
## Generic Request Factory Function
This factory function `createRequest` allows for the creation of `Request` instances with default configurations and custom interceptors for request and response handling.
### Function Signature
`createRequest(defaultConfig: RequestConfig): Request`
### Request Interceptor
- Adds an `Authorization` header with a Bearer token if available from the user store.
### Response Interceptor
- Handles HTTP status codes, showing a toast for codes outside the 2xx range.
- Processes custom response codes, displaying an error message if `code` is not 200.
- Returns the `data` from the response if successful.
- Implements retry logic for failed requests based on `extra.retryCount` and `extra.retryDelay`.
- Shows a toast with the error message for request failures.
### Example Usage
```ts
// @/utils/request.ts
import { Request, type RequestConfig } from 'sard-uniapp'
import { useUserStore } from '@/stores/user'
const errToastDuration = 5000
function createRequest(defaultConfig: RequestConfig) {
const request = new Request(defaultConfig)
// Request interceptor
request.interceptors.request.use((config) => {
const userStore = useUserStore()
if (userStore.token) {
config.header.Authorization = 'Bearer ' + userStore.token
}
return config
})
// Response interceptor
request.interceptors.response.use(
(response) => {
if (response.statusCode < 200 || response.statusCode >= 300) {
uni.showToast({
title: 'Error: statusCode ' + response.statusCode,
icon: 'none',
duration: errToastDuration,
})
return Promise.reject(response.errMsg)
}
const { code, data, message = 'error' } = response.data || {}
if (code !== 200) {
uni.showToast({
title: message,
icon: 'none',
duration: errToastDuration,
})
return Promise.reject(message)
}
return data
},
async ({ config, errMsg }) => {
const extra = config.extra
if (extra.retryCount && --extra.retryCount > 0) {
return new Promise((resolve) => setTimeout(resolve, extra.retryDelay || 1000)).then(() => request.request(config))
}
uni.showToast({
title: errMsg,
icon: 'none',
duration: errToastDuration,
})
return Promise.reject(errMsg)
},
)
return request
}
```
```
--------------------------------
### Global Theme Customization with CSS Variables
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/guide/theme.md
Apply global theme changes by importing sard-uniapp's stylesheets and overriding CSS variables like `--sar-primary` within the `page` and `.sar-portal` selectors in your `App.vue` file.
```html
```
--------------------------------
### Popup Component API
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/popup.md
This section details the properties and slots available for the Popup component.
```APIDOC
## Popup Component API
### PopupProps
| Property | Description | Type | Default |
|---|---|---|---|
| `root-class` | Component root element class name | `string` | - |
| `root-style` | Component root element style | `StyleValue` | - |
| `visible` (v-model) | Whether the popup is visible | `boolean` | `false` |
| `duration` | Animation duration for showing/hiding, in ms | `number` | `300` |
| `effect` | Show/hide effect | `'slide-top' | 'slide-right' | 'slide-bottom' | 'slide-left' | 'zoom' | 'fade'` | `'fade'` |
| `overlay` | Whether to display the overlay | `boolean` | `true` |
| `overlay-class` | Class name added to the overlay | `string` | - |
| `overlay-style` | Style added to the overlay | `string` | - |
| `background` | Overlay background color | `string` | - |
| `transparent` | Transparent overlay | `boolean` | `false` |
| `overlay-closable` (1.22+) | Whether to close on overlay click | `boolean` | `true` |
| `keep-render` (1.24.3+) | Always keep the component rendered, even when hidden | `boolean` | `false` |
| `lock-scroll` (1.25.5+) | Whether to prevent page scrolling when the popup is shown | `boolean` | `true` |
| `back-press` (1.25.7+) | Intercept back button press when popup is shown (`close`: close popup, `back`: go back a page (only in mini-programs)) | `'close' | 'back'` | `'close'` |
### PopupSlots
| Slot | Description | Props |
|---|---|---|
| `default` | Custom default content | - |
```
--------------------------------
### Basic CascaderPopout Usage
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/cascader-popout.md
Use v-model for two-way binding of the current value and v-model:visible to control the popup's visibility.
```vue
```
--------------------------------
### Select Option Keys Interface
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/select.md
Defines the structure for custom field mapping in the `options` prop of the Select component.
```typescript
interface OptionKeys {
label?: string
value?: string
children?: string
}
```
--------------------------------
### Provide and Inject Locale Data
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/guide/i18n.md
The `useLocaleProvide` hook sets up default language packs and injects locale information globally. It requires the app instance, a map of languages, and the default locale key.
```ts
// main.ts
import zhCN from 'sard-uniapp/components/locale/lang/zh-CN'
import enUS from 'sard-uniapp/components/locale/lang/en-US'
const app = createSSRApp(App)
useLocaleProvide(
app,
{
zhCN,
enUS,
},
'zhCN',
)
```
```js
// main.ts
import zhCN from 'sard-uniapp/components/locale/lang/zh-CN'
import enUS from 'sard-uniapp/components/locale/lang/en-US'
const app = createSSRApp(App)
useLocaleProvide(
app,
{
zhCN,
enUS,
},
'zhCN',
)
```
--------------------------------
### Border Color Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
SCSS utility classes for setting border colors, including transparent, inherit, white, black, and theme-specific colors like base, primary, secondary, etc., referencing Sard Uniapp's CSS variables.
```scss
.border-current {
border-color: currentColor !important;
}
.border-transparent {
border-color: transparent !important;
}
.border-inherit {
border-color: inherit !important;
}
.border-white {
border-color: white !important;
}
.border-black {
border-color: black !important;
}
.border-base {
border-color: var(--sar-border-color) !important;
}
.border-primary {
border-color: var(--sar-primary) !important;
}
.border-secondary {
border-color: var(--sar-secondary) !important;
}
.border-success {
border-color: var(--sar-success) !important;
}
.border-info {
border-color: var(--sar-info) !important;
}
.border-warning {
border-color: var(--sar-warning) !important;
}
.border-danger {
border-color: var(--sar-danger) !important;
}
```
--------------------------------
### PickerPopout Emits
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/picker-popout.md
Events emitted by the PickerPopout component.
```APIDOC
## PickerPopoutEmits
| Event | Description | Type |
| ----------------------------------- | -------------------------------------------- | ------------------------ |
| update:model-value | Triggered when the picker input value changes | `(value: any) => void` |
| change | Triggered when the picker input value changes | `(value: any) => void` |
| update:visible | Triggered when the popup is shown/hidden | `(visible: boolean) => void` |
| confirm 1.22.1+ | Triggered when the confirm button is clicked | `() => void` |
| visible-hook 1.22.1+ | Triggered when the transition hook state changes | `(name: TransitionHookName) => void` |
| before-enter 1.22.1+ | Triggered before the enter transition starts | `() => void` |
| enter 1.22.1+ | Triggered when the enter transition starts | `() => void` |
| after-enter 1.22.1+ | Triggered when the enter transition ends | `() => void` |
| enter-cancelled 1.22.1+ | Triggered when the enter transition is cancelled | `() => void` |
| before-leave 1.22.1+ | Triggered before the leave transition starts | `() => void` |
| leave 1.22.1+ | Triggered when the leave transition starts | `() => void` |
| after-leave 1.22.1+ | Triggered when the leave transition ends | `() => void` |
| leave-cancelled 1.22.1+ | Triggered when the leave transition is cancelled | `() => void` |
```
--------------------------------
### Import ScrollList Component
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/scroll-list.md
Import the ScrollList component from the sard-uniapp library. This is the initial step to use the component in your project.
```javascript
import ScrollList from 'sard-uniapp/components/scroll-list/scroll-list.vue'
```
--------------------------------
### Border Radius Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
SCSS utility classes for applying border radius, mapping to Sard Uniapp's CSS variables for various sizes like xs, sm, default, lg, xl, and full.
```scss
.rounded-xs {
border-radius: var(--sar-rounded-xs) !important;
}
.rounded-sm {
border-radius: var(--sar-rounded-sm) !important;
}
.rounded {
border-radius: var(--sar-rounded) !important;
}
.rounded-lg {
border-radius: var(--sar-rounded-lg) !important;
}
.rounded-xl {
border-radius: var(--sar-rounded-xl) !important;
}
.rounded-full {
border-radius: var(--sar-rounded-full) !important;
}
// ...
```
--------------------------------
### Imperative Popup Display
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/popup.md
Use the `popup` method to display a popup after setting up a `sar-popup-agent`. This method allows for programmatic control over popup visibility.
```vue
<<< @demo/popup/demo/Imperative.vue
```
--------------------------------
### Font Weight Utility Classes
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/utilities/atomic-css.md
SCSS utility classes for setting font weight, mapping to Sard Uniapp's CSS variables for bold, normal, and light weights.
```scss
.font-bold {
font-weight: var(--sar-font-bold) !important;
}
.font-normal {
font-weight: var(--sar-font-normal) !important;
}
.font-light {
font-weight: var(--sar-font-light) !important;
}
```
--------------------------------
### CalendarInput Emits
Source: https://github.com/sutras/sard-uniapp/blob/main/packages/docs/components/calendar-input.md
Emits available for the CalendarInput component, inheriting from CalendarPopoutEmits.
```APIDOC
## CalendarInputEmits
Inherits [`CalendarPopoutEmits`](./calendar-popout#CalendarPopoutEmits)
```