Skip to content

Commit 67e4bc5

Browse files
feat(Affix): init affix (#128)
* init: Affix
1 parent e72cb4e commit 67e4bc5

File tree

6 files changed

+391
-85
lines changed

6 files changed

+391
-85
lines changed

components.d.ts

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {}
77

88
declare module '@vue/runtime-core' {
99
export interface GlobalComponents {
10+
'Affix.story': typeof import('./src/components/Navigation/Affix/affix.story.vue')['default']
1011
'Alert.story': typeof import('./src/components/Feedback/alert.story.vue')['default']
1112
'Autocomplete.story': typeof import('./src/components/Form/autocomplete.story.vue')['default']
1213
'Avatar.story': typeof import('./src/components/Data/avatar.story.vue')['default']
@@ -28,90 +29,12 @@ declare module '@vue/runtime-core' {
2829
Controls: typeof import('./src/components/Feedback/MessageBox/controls.vue')['default']
2930
'DatePicker.story': typeof import('./src/components/Form/datePicker.story.vue')['default']
3031
'DateTimePicker.story': typeof import('./src/components/Form/dateTimePicker.story.vue')['default']
32+
Demo: typeof import('./src/components/Navigation/Affix/demo.vue')['default']
3133
'Descriptions.story': typeof import('./src/components/Data/descriptions.story.vue')['default']
3234
'Dialog.story': typeof import('./src/components/Feedback/dialog.story.vue')['default']
3335
'Divider.story': typeof import('./src/components/Others/Divider/divider.story.vue')['default']
3436
'Drawer.story': typeof import('./src/components/Feedback/Drawer/drawer.story.vue')['default']
3537
'Dropdown.story': typeof import('./src/components/Navigation/Dropdown/dropdown.story.vue')['default']
36-
ElAlert: typeof import('element-plus/es')['ElAlert']
37-
ElAside: typeof import('element-plus/es')['ElAside']
38-
ElAutocomplete: typeof import('element-plus/es')['ElAutocomplete']
39-
ElAvatar: typeof import('element-plus/es')['ElAvatar']
40-
ElBadge: typeof import('element-plus/es')['ElBadge']
41-
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb']
42-
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem']
43-
ElButton: typeof import('element-plus/es')['ElButton']
44-
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
45-
ElCalendar: typeof import('element-plus/es')['ElCalendar']
46-
ElCard: typeof import('element-plus/es')['ElCard']
47-
ElCarousel: typeof import('element-plus/es')['ElCarousel']
48-
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
49-
ElCascader: typeof import('element-plus/es')['ElCascader']
50-
ElCascaderPanel: typeof import('element-plus/es')['ElCascaderPanel']
51-
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
52-
ElCheckboxButton: typeof import('element-plus/es')['ElCheckboxButton']
53-
ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
54-
ElCheckTag: typeof import('element-plus/es')['ElCheckTag']
55-
ElCol: typeof import('element-plus/es')['ElCol']
56-
ElCollapse: typeof import('element-plus/es')['ElCollapse']
57-
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
58-
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
59-
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
60-
ElContainer: typeof import('element-plus/es')['ElContainer']
61-
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
62-
ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
63-
ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
64-
ElDialog: typeof import('element-plus/es')['ElDialog']
65-
ElDivider: typeof import('element-plus/es')['ElDivider']
66-
ElDrawer: typeof import('element-plus/es')['ElDrawer']
67-
ElDropdown: typeof import('element-plus/es')['ElDropdown']
68-
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
69-
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
70-
ElEmpty: typeof import('element-plus/es')['ElEmpty']
71-
ElFooter: typeof import('element-plus/es')['ElFooter']
72-
ElForm: typeof import('element-plus/es')['ElForm']
73-
ElFormItem: typeof import('element-plus/es')['ElFormItem']
74-
ElHeader: typeof import('element-plus/es')['ElHeader']
75-
ElIcon: typeof import('element-plus/es')['ElIcon']
76-
ElImage: typeof import('element-plus/es')['ElImage']
77-
ElInput: typeof import('element-plus/es')['ElInput']
78-
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
79-
ElLink: typeof import('element-plus/es')['ElLink']
80-
ElMain: typeof import('element-plus/es')['ElMain']
81-
ElMenu: typeof import('element-plus/es')['ElMenu']
82-
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
83-
ElMenuItemGroup: typeof import('element-plus/es')['ElMenuItemGroup']
84-
ElOption: typeof import('element-plus/es')['ElOption']
85-
ElOptionGroup: typeof import('element-plus/es')['ElOptionGroup']
86-
ElPageHeader: typeof import('element-plus/es')['ElPageHeader']
87-
ElPagination: typeof import('element-plus/es')['ElPagination']
88-
ElProgress: typeof import('element-plus/es')['ElProgress']
89-
ElRadio: typeof import('element-plus/es')['ElRadio']
90-
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
91-
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
92-
ElRate: typeof import('element-plus/es')['ElRate']
93-
ElResult: typeof import('element-plus/es')['ElResult']
94-
ElRow: typeof import('element-plus/es')['ElRow']
95-
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
96-
ElSelect: typeof import('element-plus/es')['ElSelect']
97-
ElSelectV2: typeof import('element-plus/es')['ElSelectV2']
98-
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
99-
ElSkeletonItem: typeof import('element-plus/es')['ElSkeletonItem']
100-
ElSlider: typeof import('element-plus/es')['ElSlider']
101-
ElSpace: typeof import('element-plus/es')['ElSpace']
102-
ElStep: typeof import('element-plus/es')['ElStep']
103-
ElSteps: typeof import('element-plus/es')['ElSteps']
104-
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
105-
ElSwitch: typeof import('element-plus/es')['ElSwitch']
106-
ElTable: typeof import('element-plus/es')['ElTable']
107-
ElTabPane: typeof import('element-plus/es')['ElTabPane']
108-
ElTabs: typeof import('element-plus/es')['ElTabs']
109-
ElTag: typeof import('element-plus/es')['ElTag']
110-
ElTimeline: typeof import('element-plus/es')['ElTimeline']
111-
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
112-
ElTimePicker: typeof import('element-plus/es')['ElTimePicker']
113-
ElTimeSelect: typeof import('element-plus/es')['ElTimeSelect']
114-
ElTooltip: typeof import('element-plus/es')['ElTooltip']
11538
'Empty.story': typeof import('./src/components/Data/empty.story.vue')['default']
11639
'Form.story': typeof import('./src/components/Form/Form/form.story.vue')['default']
11740
HstColor: typeof import('./src/controls-components/HstColor.vue')['default']
@@ -156,10 +79,5 @@ declare module '@vue/runtime-core' {
15679
'TimeSelect.story': typeof import('./src/components/Form/TimeSelect/timeSelect.story.vue')['default']
15780
'Tooltip.story': typeof import('./src/components/Feedback/Tooltip/tooltip.story.vue')['default']
15881
'Transfer.story': typeof import('./src/components/Form/Transfer/transfer.story.vue')['default']
159-
'Upload.story': typeof import('./src/components/Form/Upload/upload.story.vue')['default']
160-
}
161-
export interface ComponentCustomProperties {
162-
vInfiniteScroll: typeof import('element-plus/es')['ElInfiniteScroll']
163-
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
16482
}
16583
}
Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,134 @@
1-
## Message Attributes
1+
---
2+
title: Message
3+
lang: en-US
4+
---
5+
6+
# Message
7+
8+
Used to show feedback after an activity. The difference with Notification is that the latter is often used to show a system level passive notification.
9+
10+
## Basic usage
11+
12+
Displays at the top, and disappears after 3 seconds.
13+
14+
:::demo The setup of Message is very similar to notification, so parts of the options won't be explained in detail here. You can check the options table below combined with notification doc to understand it. Element Plus has registered a `$message` method for invoking. Message can take a string or a VNode as parameter, and it will be shown as the main body.
15+
16+
message/basic
17+
18+
:::
19+
20+
## Types
21+
22+
Used to show the feedback of Success, Warning, Message and Error activities.
23+
24+
:::demo When you need more customizations, Message component can also take an object as parameter. For example, setting value of `type` can define different types, and its default is `info`. In such cases the main body is passed in as the value of `message`. Also, we have registered methods for different types, so you can directly call it without passing a type like `open4`.
25+
26+
message/different-types
27+
28+
:::
29+
30+
## Closable
31+
32+
A close button can be added.
33+
34+
:::demo A default Message cannot be closed manually. If you need a closable message, you can set `showClose` field. Besides, same as notification, message has a controllable `duration`. Default duration is 3000 ms, and it won't disappear when set to `0`.
35+
36+
message/closable
37+
38+
:::
39+
40+
## Centered text
41+
42+
Use the `center` attribute to center the text.
43+
44+
:::demo
45+
46+
message/centered-content
47+
48+
:::
49+
50+
## Use HTML string
51+
52+
`message` supports HTML string.
53+
54+
:::demo Set `dangerouslyUseHTMLString` to true and `message` will be treated as an HTML string.
55+
56+
message/raw-html
57+
58+
:::
59+
60+
:::warning
61+
62+
Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content.
63+
64+
:::
65+
66+
## Grouping
67+
68+
merge messages with the same content.
69+
70+
:::demo Set `grouping` to true and the same content of `message` will be merged.
71+
72+
message/grouping
73+
74+
:::
75+
76+
## Global method
77+
78+
Element Plus has added a global method `$message` for `app.config.globalProperties`. So in a vue instance you can call `Message` like what we did in this page.
79+
80+
## Local import
81+
82+
```ts
83+
// import { ElMessage } from 'element-plus'
84+
```
85+
86+
In this case you should call `ElMessage(options)`. We have also registered methods for different types, e.g. `ElMessage.success(options)`. You can call `ElMessage.closeAll()` to manually close all the instances.
87+
88+
## App context inheritance <el-tag> >= 2.0.3</el-tag>
89+
90+
Now message accepts a `context` as second parameter of the message constructor which allows you to inject current app's context to message which allows you to inherit all the properties of the app.
91+
92+
You can use it like this:
93+
94+
:::tip
95+
96+
If you globally registered ElMessage component, it will automatically inherit your app context.
97+
98+
:::
99+
100+
```ts
101+
import { getCurrentInstance } from 'vue'
102+
import { ElMessage } from 'element-plus'
103+
104+
// in your setup method
105+
const { appContext } = getCurrentInstance()!
106+
ElMessage({}, appContext)
107+
```
108+
109+
## Message API
110+
111+
### Options
112+
113+
| Attribute | Description | Type | Default |
114+
| -------------------------- | ------------------------------------------------------------------------------ | --------------------------------------------- | --------------- |
115+
| `message` | message text | `string \| VNode \| (() => VNode)` ||
116+
| `type` | message type | `'success' \| 'warning' \| 'info' \| 'error'` | `'info'` |
117+
| `icon` | custom icon component, overrides `type` | `string \| Component` ||
118+
| `dangerouslyUseHTMLString` | whether `message` is treated as HTML string | `boolean` | `false` |
119+
| `custom-class` | custom class name for Message | `string` ||
120+
| `duration` | display duration, millisecond. If set to 0, it will not turn off automatically | `number` | `3000` |
121+
| `show-close` | whether to show a close button | `boolean` | `false` |
122+
| `center` | whether to center the text | `boolean` | `false` |
123+
| `on-close` | callback function when closed with the message instance as the parameter | `function` ||
124+
| `offset` | set the distance to the top of viewport | `number` | `20` |
125+
| `appendTo` | set the root element for the message | `string \| HTMLElement` | `document.body` |
126+
| `grouping` | merge messages with the same content, type of VNode message is not supported | `boolean` | `false` |
127+
128+
### Methods
129+
130+
`Message` and `this.$message` returns the current Message instance. To manually close the instance, you can call `close` on it.
131+
132+
| Method | Description |
133+
| ------- | ----------------- |
134+
| `close` | close the Message |

src/components/Feedback/Notification/notification.story.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import type { NotificationProps } from 'element-plus'
3+
import { ElNotification } from 'element-plus'
34
import { positionList, typeList } from './constants'
45
import { isAttribute } from '@/utils'
56
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Affix
3+
lang: en-US
4+
---
5+
6+
# Affix
7+
8+
Fix the element to a specific visible area.
9+
10+
## Basic Usage
11+
12+
Affix is fixed at the top of the page by default.
13+
14+
:::demo You can set `offset` attribute to change the offset top,the default value is 0.
15+
16+
affix/basic
17+
18+
:::
19+
20+
## Target Container
21+
22+
You can set `target` attribute to keep the affix in the container at all times. It will be hidden if out of range.
23+
24+
:::demo Please notice that the container avoid having scrollbar.
25+
26+
affix/target
27+
28+
:::
29+
30+
## Fixed Position
31+
32+
The affix component provides two fixed positions: `top` and `bottom`.
33+
34+
:::demo You can set `position` attribute to change the fixed position, the default value is `top`.
35+
36+
affix/fixed
37+
38+
:::
39+
40+
## Affix API
41+
42+
### Affix Attributes
43+
44+
| Name | Description | Type | Default | Required |
45+
| ---------- | -------------------------------- | -------------------------- | ------- | -------- |
46+
| `offset` | offset distance. | ^[number] | `0` | No |
47+
| `position` | position of affix. | ^[enum]`'top' \| 'bottom'` | `'top'` | No |
48+
| `target` | target container. (CSS selector) | ^[string] || No |
49+
| `z-index` | `z-index` of affix | ^[number] | `100` | No |
50+
51+
### Affix Events
52+
53+
| Name | Description | Type |
54+
| -------- | ---------------------------------- | ------------------------------------------------------------------- |
55+
| `change` | triggers when fixed state changed. | ^[Function]`(fixed: boolean) => void` |
56+
| `scroll` | triggers when scrolling. | ^[Function]`(value: { scrollTop: number, fixed: boolean }) => void` |
57+
58+
### Affix Exposes
59+
60+
| Method | Description | Type |
61+
| ------------ | --------------------------- | ----------------------- |
62+
| `update` | update affix state manually | ^[Function]`() => void` |
63+
| `updateRoot` | update rootRect info | ^[Function]`() => void` |
64+
65+
### Affix Slots
66+
67+
| Name | Description |
68+
| --------- | -------------------------- |
69+
| `default` | customize default content. |

0 commit comments

Comments
 (0)