@fluentui/react-link 0.0.0-nightly-20220302-0405.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +3523 -0
- package/CHANGELOG.md +1263 -0
- package/LICENSE +15 -0
- package/MIGRATION.md +33 -0
- package/README.md +32 -0
- package/SPEC.md +210 -0
- package/dist/react-link.d.ts +69 -0
- package/lib/Link.d.ts +1 -0
- package/lib/Link.js +2 -0
- package/lib/Link.js.map +1 -0
- package/lib/components/Link/Link.d.ts +6 -0
- package/lib/components/Link/Link.js +15 -0
- package/lib/components/Link/Link.js.map +1 -0
- package/lib/components/Link/Link.types.d.ts +33 -0
- package/lib/components/Link/Link.types.js +2 -0
- package/lib/components/Link/Link.types.js.map +1 -0
- package/lib/components/Link/index.d.ts +6 -0
- package/lib/components/Link/index.js +7 -0
- package/lib/components/Link/index.js.map +1 -0
- package/lib/components/Link/renderLink.d.ts +5 -0
- package/lib/components/Link/renderLink.js +15 -0
- package/lib/components/Link/renderLink.js.map +1 -0
- package/lib/components/Link/useLink.d.ts +8 -0
- package/lib/components/Link/useLink.js +36 -0
- package/lib/components/Link/useLink.js.map +1 -0
- package/lib/components/Link/useLinkState.d.ts +6 -0
- package/lib/components/Link/useLinkState.js +59 -0
- package/lib/components/Link/useLinkState.js.map +1 -0
- package/lib/components/Link/useLinkStyles.d.ts +3 -0
- package/lib/components/Link/useLinkStyles.js +83 -0
- package/lib/components/Link/useLinkStyles.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib-commonjs/Link.d.ts +1 -0
- package/lib-commonjs/Link.js +10 -0
- package/lib-commonjs/Link.js.map +1 -0
- package/lib-commonjs/components/Link/Link.d.ts +6 -0
- package/lib-commonjs/components/Link/Link.js +26 -0
- package/lib-commonjs/components/Link/Link.js.map +1 -0
- package/lib-commonjs/components/Link/Link.types.d.ts +33 -0
- package/lib-commonjs/components/Link/Link.types.js +6 -0
- package/lib-commonjs/components/Link/Link.types.js.map +1 -0
- package/lib-commonjs/components/Link/index.d.ts +6 -0
- package/lib-commonjs/components/Link/index.js +20 -0
- package/lib-commonjs/components/Link/index.js.map +1 -0
- package/lib-commonjs/components/Link/renderLink.d.ts +5 -0
- package/lib-commonjs/components/Link/renderLink.js +26 -0
- package/lib-commonjs/components/Link/renderLink.js.map +1 -0
- package/lib-commonjs/components/Link/useLink.d.ts +8 -0
- package/lib-commonjs/components/Link/useLink.js +47 -0
- package/lib-commonjs/components/Link/useLink.js.map +1 -0
- package/lib-commonjs/components/Link/useLinkState.d.ts +6 -0
- package/lib-commonjs/components/Link/useLinkState.js +69 -0
- package/lib-commonjs/components/Link/useLinkState.js.map +1 -0
- package/lib-commonjs/components/Link/useLinkStyles.d.ts +3 -0
- package/lib-commonjs/components/Link/useLinkStyles.js +95 -0
- package/lib-commonjs/components/Link/useLinkStyles.js.map +1 -0
- package/lib-commonjs/index.d.ts +1 -0
- package/lib-commonjs/index.js +10 -0
- package/lib-commonjs/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@fluentui/react-link
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
MIT License
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
|
+
|
|
15
|
+
Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Link Migration
|
|
2
|
+
|
|
3
|
+
## STATUS: WIP 🚧
|
|
4
|
+
|
|
5
|
+
This Migration guide is a work in progress and is not yet ready for use.
|
|
6
|
+
|
|
7
|
+
## Migration from v8
|
|
8
|
+
|
|
9
|
+
The existing `Link` control supports a very similar set of props to the one being proposed with a few differences that are outlined below:
|
|
10
|
+
|
|
11
|
+
- `componentRef` => NOT SUPPORTED - use regular `ref` instead.
|
|
12
|
+
- `styles` => NOT SUPPORTED - use new styling system via `tokens` instead.
|
|
13
|
+
- `theme` => NOT SUPPORTED
|
|
14
|
+
- `underline` => `inline`
|
|
15
|
+
|
|
16
|
+
## Migration from v0
|
|
17
|
+
|
|
18
|
+
v0 does not currently export a `Link` component.
|
|
19
|
+
|
|
20
|
+
## Property mapping
|
|
21
|
+
|
|
22
|
+
| v8 `Link` | Converged `Link` |
|
|
23
|
+
| -------------- | ---------------- |
|
|
24
|
+
| `componentRef` | - |
|
|
25
|
+
| `disabled` | `disabled` |
|
|
26
|
+
| `href` | `href` |
|
|
27
|
+
| `onClick` | `onClick` |
|
|
28
|
+
| `rel` | `rel` |
|
|
29
|
+
| `styles` | - |
|
|
30
|
+
| `target` | `target` |
|
|
31
|
+
| `theme` | - |
|
|
32
|
+
| `type` | `type` |
|
|
33
|
+
| `underline` | `inline` |
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @fluentui/react-link
|
|
2
|
+
|
|
3
|
+
**Link components for [Fluent UI](https://dev.microsoft.com/fluentui)**
|
|
4
|
+
|
|
5
|
+
The Link component references data that a user can follow by clicking or tapping it.
|
|
6
|
+
|
|
7
|
+
## STATUS: WIP 🚧
|
|
8
|
+
|
|
9
|
+
These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
To import Link:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { Link } from '@fluentui/react-link';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Once the Link component graduates to a production release, the component will be available at:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { Link } from '@fluentui/react-components';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Examples
|
|
26
|
+
|
|
27
|
+
```jsx
|
|
28
|
+
<Link>This is a link</Link>
|
|
29
|
+
<Link href="https://www.bing.com">This is a link</Link>
|
|
30
|
+
<Link href="https://www.bing.com" disabled>This is a link</Link>
|
|
31
|
+
<Link href="https://www.bing.com" target="_blank">This is a link</Link>
|
|
32
|
+
```
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Link
|
|
2
|
+
|
|
3
|
+
**GitHub Epic issue** - [Link Convergence #16572](https://github.com/microsoft/fluentui/issues/16572)
|
|
4
|
+
|
|
5
|
+
## Background
|
|
6
|
+
|
|
7
|
+
The `Link` component references data that a user can follow by clicking or tapping it.
|
|
8
|
+
|
|
9
|
+
## Prior Art
|
|
10
|
+
|
|
11
|
+
### Open UI
|
|
12
|
+
|
|
13
|
+
The Open UI [Link Research](https://open-ui.org/components/link.research) page (currently in PR: https://github.com/WICG/open-ui/pull/253), shows how the `Link` component is used in UI platforms across the web. The consensus across libraries seems to center around a simple interface with few variants that mostly attempt to support the functionality of the `<a>` HTML tag.
|
|
14
|
+
|
|
15
|
+
### Comparison of v8 and v0
|
|
16
|
+
|
|
17
|
+
The existing components are:
|
|
18
|
+
|
|
19
|
+
- v8 - [Link](https://developer.microsoft.com/en-us/fluentui#/controls/web/link)
|
|
20
|
+
- v0 - v0 does not currently export a `Link` component
|
|
21
|
+
|
|
22
|
+
## Sample Code
|
|
23
|
+
|
|
24
|
+
Basic examples:
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
<Link>This is a link</Link>
|
|
28
|
+
<Link href="https://www.bing.com">This is a link</Link>
|
|
29
|
+
<Link href="https://www.bing.com" disabled>This is a link</Link>
|
|
30
|
+
<Link href="https://www.bing.com" target="_blank">This is a link</Link>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Variants
|
|
34
|
+
|
|
35
|
+
### Default vs inline
|
|
36
|
+
|
|
37
|
+
A `Link` has two decoration variants depending on where it's used.
|
|
38
|
+
|
|
39
|
+
By `default`, the `Link` should be limited to homogeneous surface areas where everything is clickable in the space and should appear as lacking an underline.
|
|
40
|
+
|
|
41
|
+
A second `inline` variant is provided for scenarios where body text is going to be used alongside a `Link`. This variant adds an underline to add a separate visual distinction in addition to color for contrast purposes.
|
|
42
|
+
|
|
43
|
+
### Anchor vs button
|
|
44
|
+
|
|
45
|
+
A `Link` renders as different HTML tags depending on the whether a value has been passed for the `href` property or not. If a value has been passed to the `href` property, then the `Link` renders as an `<a>` HTML tag. Conversely, if the `href` property is left `undefined` the `Link` renders as a `<button>` HTML tag.
|
|
46
|
+
|
|
47
|
+
The `Link` can also be custom rendered as something entirely different by replacing the `root` slot with the preferred element to be rendered via the `as` prop.
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
### Slots
|
|
52
|
+
|
|
53
|
+
- `root` - The outer container representing the `Link` itself that wraps everything passed via the `children` prop.
|
|
54
|
+
|
|
55
|
+
### Props
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
export type LinkProps = ComponentProps &
|
|
59
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLElement> &
|
|
60
|
+
Omit<React.ButtonHTMLAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLElement>, 'type'> & {
|
|
61
|
+
/**
|
|
62
|
+
* URL the link points to. If not provided, the link renders as a button (unless that behavior is
|
|
63
|
+
* overridden using `as`).
|
|
64
|
+
*/
|
|
65
|
+
href?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Click handler for the link.
|
|
69
|
+
*/
|
|
70
|
+
onClick?: (event: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement | HTMLElement>) => void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Relationship to the linked URL (can be a space-separated list).
|
|
74
|
+
* Most common values are `noreferrer` and/or `noopener`.
|
|
75
|
+
* This prop is only applied if `href` is set.
|
|
76
|
+
*/
|
|
77
|
+
rel?: string;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Where to open the linked URL. Common values are `_blank` (a new tab or window),
|
|
81
|
+
* `_self` (the current window/context), `_parent`, and `_top`.
|
|
82
|
+
* This prop is only applied if `href` is set.
|
|
83
|
+
*/
|
|
84
|
+
target?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Built-in HTML attribute with different behavior depending on how the link is rendered.
|
|
88
|
+
* If rendered as `<a>`, hints at the MIME type.
|
|
89
|
+
* If rendered as `<button>`, override the type of button (`button` is the default).
|
|
90
|
+
*/
|
|
91
|
+
type?: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A link can appear either with its default style or subtle.
|
|
95
|
+
* If not specified, the link appears with its default styling.
|
|
96
|
+
*/
|
|
97
|
+
appearance?: 'subtle';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether the link is disabled.
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
disabled?: boolean;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* When set, allows the link to be focusable even when it has been disabled. This is used in scenarios where it is
|
|
107
|
+
* important to keep a consistent tab order for screen reader and keyboard users.
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
disabledFocusable?: boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* If true, changes styling when the link is being used alongside other text content.
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
inline?: boolean;
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Styling Tokens
|
|
121
|
+
|
|
122
|
+
TBD once we decide on component tokens work.
|
|
123
|
+
|
|
124
|
+
## Structure
|
|
125
|
+
|
|
126
|
+
For `Links` rendering as `<a>`:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<a class="root" href={href}>
|
|
130
|
+
{children}
|
|
131
|
+
</a>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
For `Links` rendering as anything other than `<a>` (the example below uses `<button>`):
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
<button class="root" role="link">
|
|
138
|
+
{children}
|
|
139
|
+
</button>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Migration
|
|
143
|
+
|
|
144
|
+
See [MIGRATION.md](https://github.com/microsoft/fluentui/blob/master/packages/react-link/MIGRATION.md).
|
|
145
|
+
|
|
146
|
+
## Behaviors
|
|
147
|
+
|
|
148
|
+
### States
|
|
149
|
+
|
|
150
|
+
The following section describes the different states in which a `Link` can be throughout the course of interaction with it.
|
|
151
|
+
|
|
152
|
+
#### Enabled state
|
|
153
|
+
|
|
154
|
+
An enabled `Link` communicates interaction by having styling that invites the user to click/tap on it to navigate through content.
|
|
155
|
+
|
|
156
|
+
#### Disabled state
|
|
157
|
+
|
|
158
|
+
A disabled `Link` is non-interactive, disallowing the user to click/tap on it to navigate through content.
|
|
159
|
+
|
|
160
|
+
#### Hovered state
|
|
161
|
+
|
|
162
|
+
A hovered `Link` changes styling to communicate that the user has placed a cursor above it.
|
|
163
|
+
|
|
164
|
+
#### Focused state
|
|
165
|
+
|
|
166
|
+
A focused `Link` changes styling to communicate that the user has placed keyboard focus on it. This styling is usually the same to the one in the hovered state plus extra styling on the outline to indicate keyboard focus has been placed on the component.
|
|
167
|
+
|
|
168
|
+
#### Pressed state
|
|
169
|
+
|
|
170
|
+
A pressed `Link` changes styling to communicate that the user is currently pressing it.
|
|
171
|
+
|
|
172
|
+
#### Visited state
|
|
173
|
+
|
|
174
|
+
A visited `Link` changes styling to communicate that the user has already interacted with it so its referenced content has already been accessed in the past.
|
|
175
|
+
|
|
176
|
+
### Interaction
|
|
177
|
+
|
|
178
|
+
#### Keyboard interaction
|
|
179
|
+
|
|
180
|
+
The following is a set of keys that interact with the `Link` component:
|
|
181
|
+
|
|
182
|
+
| Key | Description |
|
|
183
|
+
| ------------------------ | -------------------------------------------------- |
|
|
184
|
+
| `Enter` | Executes the `Link` and moves focus to its target. |
|
|
185
|
+
| `Shift + F10` (Optional) | Opens a context menu for the `Link`. |
|
|
186
|
+
|
|
187
|
+
#### Cursor interaction
|
|
188
|
+
|
|
189
|
+
- `mouseenter`: Should immediately change the styling of the `Link` so that it appears to be hovered.
|
|
190
|
+
- `mouseleave`: Should immediately remove the hovered styling of the `Link`.
|
|
191
|
+
- `mouseup`: If triggered while cursor is still inside of the `Link's` boundaries, then it should execute the `Link` and move focus to its target.
|
|
192
|
+
|
|
193
|
+
#### Touch interaction
|
|
194
|
+
|
|
195
|
+
The same behavior as above translated for touch events. This means that there is no equivalent for `mouseenter` and `mouseleave`, which makes it so that the hovered state cannot be accessed.
|
|
196
|
+
|
|
197
|
+
## Accessibility
|
|
198
|
+
|
|
199
|
+
### Relevant documents
|
|
200
|
+
|
|
201
|
+
- [WAI-ARIA 1.1 Spec](https://www.w3.org/TR/wai-aria-1.1/#link)
|
|
202
|
+
- [WAI-ARIA 1.1 Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.1/#link)
|
|
203
|
+
- [WAI-ARIA 1.2 Spec](https://www.w3.org/TR/wai-aria-1.2/#link)
|
|
204
|
+
- [WAI-ARIA 1.2 Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.2/#link)
|
|
205
|
+
|
|
206
|
+
### Expected behavior
|
|
207
|
+
|
|
208
|
+
- Should default to render a native `a` element unless something else has been specified for the `root` slot, in which case `role="link"` should be added to it.
|
|
209
|
+
- Should mix in the native props expected for the `a` native element.
|
|
210
|
+
- Should be keyboard tabbable and focusable.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ComponentProps } from '@fluentui/react-utilities';
|
|
2
|
+
import type { ComponentState } from '@fluentui/react-utilities';
|
|
3
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
4
|
+
import * as React_2 from 'react';
|
|
5
|
+
import type { Slot } from '@fluentui/react-utilities';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A Link is a reference to data that a user can follow by clicking or tapping it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Link: ForwardRefComponent<LinkProps>;
|
|
11
|
+
|
|
12
|
+
export declare const linkClassName = "fui-Link";
|
|
13
|
+
|
|
14
|
+
declare type LinkCommons = {
|
|
15
|
+
/**
|
|
16
|
+
* A link can appear either with its default style or subtle.
|
|
17
|
+
* If not specified, the link appears with its default styling.
|
|
18
|
+
*/
|
|
19
|
+
appearance?: 'subtle';
|
|
20
|
+
/**
|
|
21
|
+
* Whether the link is disabled.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* When set, allows the link to be focusable even when it has been disabled. This is used in scenarios where it is
|
|
27
|
+
* important to keep a consistent tab order for screen reader and keyboard users.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
disabledFocusable?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* If true, changes styling when the link is being used alongside other text content.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
inline?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export declare type LinkProps = ComponentProps<LinkSlots> & LinkCommons;
|
|
39
|
+
|
|
40
|
+
export declare type LinkSlots = {
|
|
41
|
+
/**
|
|
42
|
+
* Root of the component that renders as either an <a> or a <button> tag.
|
|
43
|
+
*/
|
|
44
|
+
root: Slot<'a', 'button'>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export declare type LinkState = ComponentState<LinkSlots> & LinkCommons;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Renders a Link component by passing the state defined props to the appropriate slots.
|
|
51
|
+
*/
|
|
52
|
+
export declare const renderLink_unstable: (state: LinkState) => JSX.Element;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Given user props, defines default props for the Link, calls useLinkState_unstable, and returns processed state.
|
|
56
|
+
* @param props - User provided props to the Link component.
|
|
57
|
+
* @param ref - User provided ref to be passed to the Link component.
|
|
58
|
+
*/
|
|
59
|
+
export declare const useLink_unstable: (props: LinkProps, ref: React_2.Ref<HTMLAnchorElement | HTMLButtonElement>) => LinkState;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The useLinkState_unstable hook processes the Link state.
|
|
63
|
+
* @param state - Link state to mutate.
|
|
64
|
+
*/
|
|
65
|
+
export declare const useLinkState_unstable: (state: LinkState) => LinkState;
|
|
66
|
+
|
|
67
|
+
export declare const useLinkStyles_unstable: (state: LinkState) => LinkState;
|
|
68
|
+
|
|
69
|
+
export { }
|
package/lib/Link.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/Link/index';
|
package/lib/Link.js
ADDED
package/lib/Link.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.js","sourceRoot":"../src/","sources":["Link.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC","sourcesContent":["export * from './components/Link/index';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LinkProps } from './Link.types';
|
|
2
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
3
|
+
/**
|
|
4
|
+
* A Link is a reference to data that a user can follow by clicking or tapping it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Link: ForwardRefComponent<LinkProps>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLink_unstable } from './useLink';
|
|
3
|
+
import { useLinkStyles_unstable } from './useLinkStyles';
|
|
4
|
+
import { renderLink_unstable } from './renderLink';
|
|
5
|
+
/**
|
|
6
|
+
* A Link is a reference to data that a user can follow by clicking or tapping it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
10
|
+
const state = useLink_unstable(props, ref);
|
|
11
|
+
useLinkStyles_unstable(state);
|
|
12
|
+
return renderLink_unstable(state); // Work around some small mismatches in inferred types which don't matter in practice
|
|
13
|
+
});
|
|
14
|
+
Link.displayName = 'Link';
|
|
15
|
+
//# sourceMappingURL=Link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Link/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,WAAjC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AACA,SAAS,mBAAT,QAAoC,cAApC;AAIA;;AAEG;;AACH,OAAO,MAAM,IAAI,gBAAmC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AAClF,QAAM,KAAK,GAAG,gBAAgB,CAAC,KAAD,EAAQ,GAAR,CAA9B;AAEA,EAAA,sBAAsB,CAAC,KAAD,CAAtB;AAEA,SAAO,mBAAmB,CAAC,KAAD,CAA1B,CALkF,CAMlF;AACD,CAPmD,CAA7C;AASP,IAAI,CAAC,WAAL,GAAmB,MAAnB","sourcesContent":["import * as React from 'react';\nimport { useLink_unstable } from './useLink';\nimport { useLinkStyles_unstable } from './useLinkStyles';\nimport { renderLink_unstable } from './renderLink';\nimport type { LinkProps } from './Link.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * A Link is a reference to data that a user can follow by clicking or tapping it.\n */\nexport const Link: ForwardRefComponent<LinkProps> = React.forwardRef((props, ref) => {\n const state = useLink_unstable(props, ref);\n\n useLinkStyles_unstable(state);\n\n return renderLink_unstable(state);\n // Work around some small mismatches in inferred types which don't matter in practice\n}) as ForwardRefComponent<LinkProps>;\n\nLink.displayName = 'Link';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
|
2
|
+
export declare type LinkSlots = {
|
|
3
|
+
/**
|
|
4
|
+
* Root of the component that renders as either an <a> or a <button> tag.
|
|
5
|
+
*/
|
|
6
|
+
root: Slot<'a', 'button'>;
|
|
7
|
+
};
|
|
8
|
+
declare type LinkCommons = {
|
|
9
|
+
/**
|
|
10
|
+
* A link can appear either with its default style or subtle.
|
|
11
|
+
* If not specified, the link appears with its default styling.
|
|
12
|
+
*/
|
|
13
|
+
appearance?: 'subtle';
|
|
14
|
+
/**
|
|
15
|
+
* Whether the link is disabled.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* When set, allows the link to be focusable even when it has been disabled. This is used in scenarios where it is
|
|
21
|
+
* important to keep a consistent tab order for screen reader and keyboard users.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabledFocusable?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* If true, changes styling when the link is being used alongside other text content.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
inline?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare type LinkProps = ComponentProps<LinkSlots> & LinkCommons;
|
|
32
|
+
export declare type LinkState = ComponentState<LinkSlots> & LinkCommons;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.types.js","sourceRoot":"../src/","sources":["components/Link/Link.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type LinkSlots = {\n /**\n * Root of the component that renders as either an <a> or a <button> tag.\n */\n root: Slot<'a', 'button'>;\n};\n\ntype LinkCommons = {\n /**\n * A link can appear either with its default style or subtle.\n * If not specified, the link appears with its default styling.\n */\n appearance?: 'subtle';\n\n /**\n * Whether the link is disabled.\n * @default false\n */\n disabled?: boolean;\n\n /**\n * When set, allows the link to be focusable even when it has been disabled. This is used in scenarios where it is\n * important to keep a consistent tab order for screen reader and keyboard users.\n * @default false\n */\n disabledFocusable?: boolean;\n\n /**\n * If true, changes styling when the link is being used alongside other text content.\n * @default false\n */\n inline?: boolean;\n};\n\nexport type LinkProps = ComponentProps<LinkSlots> & LinkCommons;\n\nexport type LinkState = ComponentState<LinkSlots> & LinkCommons;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Link/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './Link';\nexport * from './Link.types';\nexport * from './renderLink';\nexport * from './useLink';\nexport * from './useLinkState';\nexport * from './useLinkStyles';\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a Link component by passing the state defined props to the appropriate slots.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const renderLink_unstable = state => {
|
|
8
|
+
const {
|
|
9
|
+
slots,
|
|
10
|
+
slotProps
|
|
11
|
+
} = getSlots(state);
|
|
12
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=renderLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Link/renderLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,mBAAmB,GAAI,KAAD,IAAqB;AACtD,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAY,KAAZ,CAArC;AAEA,sBAAO,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,CAAP;AACD,CAJM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { LinkSlots, LinkState } from './Link.types';\n\n/**\n * Renders a Link component by passing the state defined props to the appropriate slots.\n */\nexport const renderLink_unstable = (state: LinkState) => {\n const { slots, slotProps } = getSlots<LinkSlots>(state);\n\n return <slots.root {...slotProps.root} />;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { LinkProps, LinkState } from './Link.types';
|
|
3
|
+
/**
|
|
4
|
+
* Given user props, defines default props for the Link, calls useLinkState_unstable, and returns processed state.
|
|
5
|
+
* @param props - User provided props to the Link component.
|
|
6
|
+
* @param ref - User provided ref to be passed to the Link component.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useLink_unstable: (props: LinkProps, ref: React.Ref<HTMLAnchorElement | HTMLButtonElement>) => LinkState;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getNativeElementProps } from '@fluentui/react-utilities';
|
|
2
|
+
import { useLinkState_unstable } from './useLinkState';
|
|
3
|
+
/**
|
|
4
|
+
* Given user props, defines default props for the Link, calls useLinkState_unstable, and returns processed state.
|
|
5
|
+
* @param props - User provided props to the Link component.
|
|
6
|
+
* @param ref - User provided ref to be passed to the Link component.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const useLink_unstable = (props, ref) => {
|
|
10
|
+
const {
|
|
11
|
+
appearance,
|
|
12
|
+
disabled,
|
|
13
|
+
disabledFocusable,
|
|
14
|
+
inline
|
|
15
|
+
} = props;
|
|
16
|
+
const as = props.as || (props.href ? 'a' : 'button');
|
|
17
|
+
const state = {
|
|
18
|
+
// Props passed at the top-level
|
|
19
|
+
appearance,
|
|
20
|
+
disabled,
|
|
21
|
+
disabledFocusable,
|
|
22
|
+
inline,
|
|
23
|
+
// Slots definition
|
|
24
|
+
components: {
|
|
25
|
+
root: 'a'
|
|
26
|
+
},
|
|
27
|
+
root: getNativeElementProps(as, {
|
|
28
|
+
ref,
|
|
29
|
+
...props,
|
|
30
|
+
as
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
useLinkState_unstable(state);
|
|
34
|
+
return state;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=useLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Link/useLink.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,QAAsC,2BAAtC;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AAGA;;;;AAIG;;AACH,OAAO,MAAM,gBAAgB,GAAG,CAC9B,KAD8B,EAE9B,GAF8B,KAGjB;AACb,QAAM;AAAE,IAAA,UAAF;AAAc,IAAA,QAAd;AAAwB,IAAA,iBAAxB;AAA2C,IAAA;AAA3C,MAAsD,KAA5D;AACA,QAAM,EAAE,GAAG,KAAK,CAAC,EAAN,KAAa,KAAK,CAAC,IAAN,GAAa,GAAb,GAAmB,QAAhC,CAAX;AAEA,QAAM,KAAK,GAAc;AACvB;AACA,IAAA,UAFuB;AAGvB,IAAA,QAHuB;AAIvB,IAAA,iBAJuB;AAKvB,IAAA,MALuB;AAOvB;AACA,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE;AADI,KARW;AAYvB,IAAA,IAAI,EAAE,qBAAqB,CAAC,EAAD,EAAK;AAC9B,MAAA,GAD8B;AAE9B,SAAG,KAF2B;AAG9B,MAAA;AAH8B,KAAL;AAZJ,GAAzB;AAmBA,EAAA,qBAAqB,CAAC,KAAD,CAArB;AAEA,SAAO,KAAP;AACD,CA7BM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps } from '@fluentui/react-utilities';\nimport { useLinkState_unstable } from './useLinkState';\nimport type { LinkProps, LinkState } from './Link.types';\n\n/**\n * Given user props, defines default props for the Link, calls useLinkState_unstable, and returns processed state.\n * @param props - User provided props to the Link component.\n * @param ref - User provided ref to be passed to the Link component.\n */\nexport const useLink_unstable = (\n props: LinkProps,\n ref: React.Ref<HTMLAnchorElement | HTMLButtonElement>,\n): LinkState => {\n const { appearance, disabled, disabledFocusable, inline } = props;\n const as = props.as || (props.href ? 'a' : 'button');\n\n const state: LinkState = {\n // Props passed at the top-level\n appearance,\n disabled,\n disabledFocusable,\n inline,\n\n // Slots definition\n components: {\n root: 'a',\n },\n\n root: getNativeElementProps(as, {\n ref,\n ...props,\n as,\n }),\n };\n\n useLinkState_unstable(state);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Enter, Space } from '@fluentui/keyboard-keys';
|
|
2
|
+
/**
|
|
3
|
+
* The useLinkState_unstable hook processes the Link state.
|
|
4
|
+
* @param state - Link state to mutate.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const useLinkState_unstable = state => {
|
|
8
|
+
const {
|
|
9
|
+
disabled,
|
|
10
|
+
disabledFocusable
|
|
11
|
+
} = state;
|
|
12
|
+
const {
|
|
13
|
+
onClick,
|
|
14
|
+
onKeyDown,
|
|
15
|
+
role,
|
|
16
|
+
type
|
|
17
|
+
} = state.root; // Add href and tabIndex=0 for anchor elements.
|
|
18
|
+
|
|
19
|
+
if (state.root.as === 'a') {
|
|
20
|
+
state.root.href = disabled ? undefined : state.root.href;
|
|
21
|
+
state.root.tabIndex = disabled && !disabledFocusable ? undefined : 0; // Add role="link" for disabled and disabledFocusable links.
|
|
22
|
+
|
|
23
|
+
if (disabled || disabledFocusable) {
|
|
24
|
+
state.root.role = role || 'link';
|
|
25
|
+
}
|
|
26
|
+
} // Add type="button" for button elements.
|
|
27
|
+
else {
|
|
28
|
+
state.root.type = type || 'button';
|
|
29
|
+
} // Disallow click event when component is disabled and eat events when disabledFocusable is set to true.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
state.root.onClick = ev => {
|
|
33
|
+
if (disabled || disabledFocusable) {
|
|
34
|
+
ev.preventDefault();
|
|
35
|
+
} else {
|
|
36
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(ev);
|
|
37
|
+
}
|
|
38
|
+
}; // Disallow keydown event when component is disabled and eat events when disabledFocusable is set to true.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
state.root.onKeyDown = ev => {
|
|
42
|
+
if ((disabled || disabledFocusable) && (ev.key === Enter || ev.key === Space)) {
|
|
43
|
+
ev.preventDefault();
|
|
44
|
+
ev.stopPropagation();
|
|
45
|
+
} else {
|
|
46
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev);
|
|
47
|
+
}
|
|
48
|
+
}; // Set the aria-disabled and disabled props correctly.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
state.root['aria-disabled'] = disabled || disabledFocusable;
|
|
52
|
+
|
|
53
|
+
if (state.root.as === 'button') {
|
|
54
|
+
state.root.disabled = disabled && !disabledFocusable;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return state;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=useLinkState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Link/useLinkState.ts"],"names":[],"mappings":"AACA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AAGA;;;AAGG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAgC;AACnE,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA;AAAZ,MAAkC,KAAxC;AACA,QAAM;AAAE,IAAA,OAAF;AAAW,IAAA,SAAX;AAAsB,IAAA,IAAtB;AAA4B,IAAA;AAA5B,MAAqC,KAAK,CAAC,IAAjD,CAFmE,CAInE;;AACA,MAAI,KAAK,CAAC,IAAN,CAAW,EAAX,KAAkB,GAAtB,EAA2B;AACzB,IAAA,KAAK,CAAC,IAAN,CAAW,IAAX,GAAkB,QAAQ,GAAG,SAAH,GAAe,KAAK,CAAC,IAAN,CAAW,IAApD;AACA,IAAA,KAAK,CAAC,IAAN,CAAW,QAAX,GAAsB,QAAQ,IAAI,CAAC,iBAAb,GAAiC,SAAjC,GAA6C,CAAnE,CAFyB,CAIzB;;AACA,QAAI,QAAQ,IAAI,iBAAhB,EAAmC;AACjC,MAAA,KAAK,CAAC,IAAN,CAAW,IAAX,GAAkB,IAAI,IAAI,MAA1B;AACD;AACF,GARD,CASA;AATA,OAUK;AACH,IAAA,KAAK,CAAC,IAAN,CAAW,IAAX,GAAkB,IAAI,IAAI,QAA1B;AACD,GAjBkE,CAmBnE;;;AACA,EAAA,KAAK,CAAC,IAAN,CAAW,OAAX,GAAsB,EAAD,IAAgE;AACnF,QAAI,QAAQ,IAAI,iBAAhB,EAAmC;AACjC,MAAA,EAAE,CAAC,cAAH;AACD,KAFD,MAEO;AACL,MAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAG,EAAH,CAAP;AACD;AACF,GAND,CApBmE,CA4BnE;;;AACA,EAAA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAwB,EAAD,IAAmE;AACxF,QAAI,CAAC,QAAQ,IAAI,iBAAb,MAAoC,EAAE,CAAC,GAAH,KAAW,KAAX,IAAoB,EAAE,CAAC,GAAH,KAAW,KAAnE,CAAJ,EAA+E;AAC7E,MAAA,EAAE,CAAC,cAAH;AACA,MAAA,EAAE,CAAC,eAAH;AACD,KAHD,MAGO;AACL,MAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,EAAH,CAAT;AACD;AACF,GAPD,CA7BmE,CAsCnE;;;AACA,EAAA,KAAK,CAAC,IAAN,CAAW,eAAX,IAA8B,QAAQ,IAAI,iBAA1C;;AACA,MAAI,KAAK,CAAC,IAAN,CAAW,EAAX,KAAkB,QAAtB,EAAgC;AAC9B,IAAA,KAAK,CAAC,IAAN,CAAW,QAAX,GAAsB,QAAQ,IAAI,CAAC,iBAAnC;AACD;;AAED,SAAO,KAAP;AACD,CA7CM","sourcesContent":["import * as React from 'react';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\nimport type { LinkState } from './Link.types';\n\n/**\n * The useLinkState_unstable hook processes the Link state.\n * @param state - Link state to mutate.\n */\nexport const useLinkState_unstable = (state: LinkState): LinkState => {\n const { disabled, disabledFocusable } = state;\n const { onClick, onKeyDown, role, type } = state.root;\n\n // Add href and tabIndex=0 for anchor elements.\n if (state.root.as === 'a') {\n state.root.href = disabled ? undefined : state.root.href;\n state.root.tabIndex = disabled && !disabledFocusable ? undefined : 0;\n\n // Add role=\"link\" for disabled and disabledFocusable links.\n if (disabled || disabledFocusable) {\n state.root.role = role || 'link';\n }\n }\n // Add type=\"button\" for button elements.\n else {\n state.root.type = type || 'button';\n }\n\n // Disallow click event when component is disabled and eat events when disabledFocusable is set to true.\n state.root.onClick = (ev: React.MouseEvent<HTMLAnchorElement & HTMLButtonElement>) => {\n if (disabled || disabledFocusable) {\n ev.preventDefault();\n } else {\n onClick?.(ev);\n }\n };\n\n // Disallow keydown event when component is disabled and eat events when disabledFocusable is set to true.\n state.root.onKeyDown = (ev: React.KeyboardEvent<HTMLAnchorElement & HTMLButtonElement>) => {\n if ((disabled || disabledFocusable) && (ev.key === Enter || ev.key === Space)) {\n ev.preventDefault();\n ev.stopPropagation();\n } else {\n onKeyDown?.(ev);\n }\n };\n\n // Set the aria-disabled and disabled props correctly.\n state.root['aria-disabled'] = disabled || disabledFocusable;\n if (state.root.as === 'button') {\n state.root.disabled = disabled && !disabledFocusable;\n }\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|