@availity/mui-link 0.3.0 → 0.4.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.md +12 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -4
- package/dist/index.mjs +8 -4
- package/package.json +2 -2
- package/src/lib/Link.stories.tsx +43 -10
- package/src/lib/Link.test.tsx +36 -0
- package/src/lib/Link.tsx +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.4.1](https://github.com/Availity/element/compare/@availity/mui-link@0.4.0...@availity/mui-link@0.4.1) (2024-07-22)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-icon` updated to version `0.4.0`
|
|
10
|
+
## [0.4.0](https://github.com/Availity/element/compare/@availity/mui-link@0.3.0...@availity/mui-link@0.4.0) (2024-06-10)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **mui-link:** allow link icon to display at the end ([f101b52](https://github.com/Availity/element/commit/f101b52edb293f16ee32fa942ec8e71675ee28c1))
|
|
16
|
+
|
|
5
17
|
## [0.3.0](https://github.com/Availity/element/compare/@availity/mui-link@0.2.9...@availity/mui-link@0.3.0) (2024-05-02)
|
|
6
18
|
|
|
7
19
|
|
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,10 @@ type LinkProps = {
|
|
|
15
15
|
onClick?: (event: React.MouseEvent, url: string) => void;
|
|
16
16
|
children?: ReactNode;
|
|
17
17
|
rel?: string;
|
|
18
|
+
/** The position of the icon relative to the text when target is `_blank`
|
|
19
|
+
*
|
|
20
|
+
* @default 'start' */
|
|
21
|
+
iconPosition?: 'start' | 'end';
|
|
18
22
|
} & Omit<LinkProps$1, 'underline' | 'noWrap' | 'variantMapping'>;
|
|
19
23
|
declare const Link: react.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
|
|
20
24
|
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ type LinkProps = {
|
|
|
15
15
|
onClick?: (event: React.MouseEvent, url: string) => void;
|
|
16
16
|
children?: ReactNode;
|
|
17
17
|
rel?: string;
|
|
18
|
+
/** The position of the icon relative to the text when target is `_blank`
|
|
19
|
+
*
|
|
20
|
+
* @default 'start' */
|
|
21
|
+
iconPosition?: 'start' | 'end';
|
|
18
22
|
} & Omit<LinkProps$1, 'underline' | 'noWrap' | 'variantMapping'>;
|
|
19
23
|
declare const Link: react.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
|
|
20
24
|
|
package/dist/index.js
CHANGED
|
@@ -94,11 +94,13 @@ var setRel = (url, target, absolute) => {
|
|
|
94
94
|
return void 0;
|
|
95
95
|
};
|
|
96
96
|
var Link = (0, import_react.forwardRef)((props, ref) => {
|
|
97
|
-
const _a = props, { href, target = "_self", children, onClick, loadApp = true, rel } = _a, rest = __objRest(_a, ["href", "target", "children", "onClick", "loadApp", "rel"]);
|
|
97
|
+
const _a = props, { href, target = "_self", children, onClick, loadApp = true, rel, iconPosition = "start" } = _a, rest = __objRest(_a, ["href", "target", "children", "onClick", "loadApp", "rel", "iconPosition"]);
|
|
98
98
|
const absolute = isAbsoluteUrl(href);
|
|
99
99
|
const encode = !(absolute || !loadApp);
|
|
100
100
|
const url = encode ? getUrl(href) : href;
|
|
101
101
|
const NewWindowIcon = target === "_blank" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_icon.OpenInNewIcon, {}) : null;
|
|
102
|
+
const startIcon = iconPosition === "start";
|
|
103
|
+
const endIcon = iconPosition === "end";
|
|
102
104
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
103
105
|
import_Link.default,
|
|
104
106
|
__spreadProps(__spreadValues({
|
|
@@ -109,9 +111,11 @@ var Link = (0, import_react.forwardRef)((props, ref) => {
|
|
|
109
111
|
}, rest), {
|
|
110
112
|
ref,
|
|
111
113
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
112
|
-
NewWindowIcon,
|
|
113
|
-
"
|
|
114
|
-
children
|
|
114
|
+
startIcon && NewWindowIcon,
|
|
115
|
+
" ",
|
|
116
|
+
children,
|
|
117
|
+
" ",
|
|
118
|
+
endIcon && NewWindowIcon
|
|
115
119
|
] })
|
|
116
120
|
})
|
|
117
121
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -61,11 +61,13 @@ var setRel = (url, target, absolute) => {
|
|
|
61
61
|
return void 0;
|
|
62
62
|
};
|
|
63
63
|
var Link = forwardRef((props, ref) => {
|
|
64
|
-
const _a = props, { href, target = "_self", children, onClick, loadApp = true, rel } = _a, rest = __objRest(_a, ["href", "target", "children", "onClick", "loadApp", "rel"]);
|
|
64
|
+
const _a = props, { href, target = "_self", children, onClick, loadApp = true, rel, iconPosition = "start" } = _a, rest = __objRest(_a, ["href", "target", "children", "onClick", "loadApp", "rel", "iconPosition"]);
|
|
65
65
|
const absolute = isAbsoluteUrl(href);
|
|
66
66
|
const encode = !(absolute || !loadApp);
|
|
67
67
|
const url = encode ? getUrl(href) : href;
|
|
68
68
|
const NewWindowIcon = target === "_blank" ? /* @__PURE__ */ jsx(OpenInNewIcon, {}) : null;
|
|
69
|
+
const startIcon = iconPosition === "start";
|
|
70
|
+
const endIcon = iconPosition === "end";
|
|
69
71
|
return /* @__PURE__ */ jsx(
|
|
70
72
|
MuiLink,
|
|
71
73
|
__spreadProps(__spreadValues({
|
|
@@ -76,9 +78,11 @@ var Link = forwardRef((props, ref) => {
|
|
|
76
78
|
}, rest), {
|
|
77
79
|
ref,
|
|
78
80
|
children: /* @__PURE__ */ jsxs("span", { children: [
|
|
79
|
-
NewWindowIcon,
|
|
80
|
-
"
|
|
81
|
-
children
|
|
81
|
+
startIcon && NewWindowIcon,
|
|
82
|
+
" ",
|
|
83
|
+
children,
|
|
84
|
+
" ",
|
|
85
|
+
endIcon && NewWindowIcon
|
|
82
86
|
] })
|
|
83
87
|
})
|
|
84
88
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-link",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Availity MUI Link Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@availity/mui-icon": "^0.
|
|
49
|
+
"@availity/mui-icon": "^0.9.0"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/lib/Link.stories.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react';
|
|
|
3
3
|
import { SystemPropsList } from '../../../../data/MuiSystemProperties';
|
|
4
4
|
import { Link, LinkProps } from './Link';
|
|
5
5
|
|
|
6
|
-
const excludedProps = [...SystemPropsList,
|
|
6
|
+
const excludedProps = [...SystemPropsList, 'align'];
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Simple link component that renders an `<a>` tag with the href formatted to leverage loadApp so the link gets loaded inside the home page's iframe
|
|
@@ -45,9 +45,17 @@ export const _Link: StoryObj<typeof Link> = {
|
|
|
45
45
|
export const _Variants: StoryObj<typeof Link> = {
|
|
46
46
|
render: () => (
|
|
47
47
|
<div>
|
|
48
|
-
<Link href=
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
<Link href="#" gutterBottom>
|
|
49
|
+
Medium standalone link (default)
|
|
50
|
+
</Link>
|
|
51
|
+
<br />
|
|
52
|
+
<Link href="#" gutterBottom variant="body2">
|
|
53
|
+
Small standalone link
|
|
54
|
+
</Link>
|
|
55
|
+
<br />
|
|
56
|
+
<Link href="#" gutterBottom variant="inherit">
|
|
57
|
+
Inline link
|
|
58
|
+
</Link>
|
|
51
59
|
</div>
|
|
52
60
|
),
|
|
53
61
|
};
|
|
@@ -60,6 +68,13 @@ export const _NewWindow: StoryObj<typeof Link> = {
|
|
|
60
68
|
},
|
|
61
69
|
};
|
|
62
70
|
|
|
71
|
+
export const _NewWindowEndIcon: StoryObj<typeof Link> = {
|
|
72
|
+
render: (args: LinkProps) => <Link {...args} loadApp={false} target="_blank" iconPosition="end" />,
|
|
73
|
+
args: {
|
|
74
|
+
children: 'Link opens in new window',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
63
78
|
export const _AbsoluteUrl: StoryObj<typeof Link> = {
|
|
64
79
|
render: (args: LinkProps) => <Link {...args} href="https://github.com/Availity" target="_blank" />,
|
|
65
80
|
args: {
|
|
@@ -79,12 +94,30 @@ export const _RelativeUrl: StoryObj<typeof Link> = {
|
|
|
79
94
|
export const _Lists: StoryObj<typeof Link> = {
|
|
80
95
|
render: () => (
|
|
81
96
|
<div>
|
|
82
|
-
<Link href=
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<
|
|
86
|
-
<Link href=
|
|
87
|
-
|
|
97
|
+
<Link href="#" gutterBottom>
|
|
98
|
+
Link 1
|
|
99
|
+
</Link>
|
|
100
|
+
<br />
|
|
101
|
+
<Link href="#" gutterBottom>
|
|
102
|
+
Link 2
|
|
103
|
+
</Link>
|
|
104
|
+
<br />
|
|
105
|
+
<Link href="#" gutterBottom>
|
|
106
|
+
Link 3
|
|
107
|
+
</Link>
|
|
108
|
+
<br />
|
|
109
|
+
<Link href="#" gutterBottom>
|
|
110
|
+
Link 4
|
|
111
|
+
</Link>
|
|
112
|
+
<br />
|
|
113
|
+
<Link href="#" gutterBottom>
|
|
114
|
+
Link 5
|
|
115
|
+
</Link>
|
|
116
|
+
<br />
|
|
117
|
+
<Link href="#" gutterBottom>
|
|
118
|
+
Link 6
|
|
119
|
+
</Link>
|
|
120
|
+
<br />
|
|
88
121
|
</div>
|
|
89
122
|
),
|
|
90
123
|
};
|
package/src/lib/Link.test.tsx
CHANGED
|
@@ -8,6 +8,42 @@ describe('Link', () => {
|
|
|
8
8
|
expect(getByText('Test')).toBeTruthy();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
test('should render icon on left if no iconPosition passed', () => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<Link target="_blank" href="#">
|
|
14
|
+
Test
|
|
15
|
+
</Link>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const spanChildren = container.getElementsByTagName('span')[0].children;
|
|
19
|
+
|
|
20
|
+
expect(spanChildren[0].tagName).toBe('svg');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should render icon on left if iconPosition is set to `start` passed', () => {
|
|
24
|
+
const { container } = render(
|
|
25
|
+
<Link target="_blank" href="#" iconPosition="start">
|
|
26
|
+
Test
|
|
27
|
+
</Link>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const spanChildren = container.getElementsByTagName('span')[0].children;
|
|
31
|
+
|
|
32
|
+
expect(spanChildren[0].tagName).toBe('svg');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should render icon on right if iconPosition is set to `end` passed', () => {
|
|
36
|
+
const { container } = render(
|
|
37
|
+
<Link target="_blank" href="#" iconPosition="end">
|
|
38
|
+
Test
|
|
39
|
+
</Link>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const spanChildren = container.getElementsByTagName('span')[0].children;
|
|
43
|
+
|
|
44
|
+
expect(spanChildren[spanChildren.length - 1].tagName).toBe('svg');
|
|
45
|
+
});
|
|
46
|
+
|
|
11
47
|
test('should render absolute url', () => {
|
|
12
48
|
const { getByRole } = render(<Link href="https://github.com/Availity">Test</Link>);
|
|
13
49
|
|
package/src/lib/Link.tsx
CHANGED
|
@@ -53,14 +53,20 @@ export type LinkProps = {
|
|
|
53
53
|
onClick?: (event: React.MouseEvent, url: string) => void;
|
|
54
54
|
children?: ReactNode;
|
|
55
55
|
rel?: string;
|
|
56
|
-
|
|
56
|
+
/** The position of the icon relative to the text when target is `_blank`
|
|
57
|
+
*
|
|
58
|
+
* @default 'start' */
|
|
59
|
+
iconPosition?: 'start' | 'end';
|
|
60
|
+
} & Omit<MuiLinkProps, 'underline' | 'noWrap' | 'variantMapping'>;
|
|
57
61
|
|
|
58
62
|
export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
59
|
-
const { href, target = '_self', children, onClick, loadApp = true, rel, ...rest } = props;
|
|
63
|
+
const { href, target = '_self', children, onClick, loadApp = true, rel, iconPosition = 'start', ...rest } = props;
|
|
60
64
|
const absolute = isAbsoluteUrl(href);
|
|
61
65
|
const encode = !(absolute || !loadApp);
|
|
62
66
|
const url = encode ? getUrl(href) : href;
|
|
63
67
|
const NewWindowIcon = target === '_blank' ? <OpenInNewIcon /> : null;
|
|
68
|
+
const startIcon = iconPosition === 'start';
|
|
69
|
+
const endIcon = iconPosition === 'end';
|
|
64
70
|
|
|
65
71
|
return (
|
|
66
72
|
<MuiLink
|
|
@@ -72,7 +78,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
72
78
|
ref={ref}
|
|
73
79
|
>
|
|
74
80
|
<span>
|
|
75
|
-
{NewWindowIcon}
|
|
81
|
+
{startIcon && NewWindowIcon} {children} {endIcon && NewWindowIcon}
|
|
76
82
|
</span>
|
|
77
83
|
</MuiLink>
|
|
78
84
|
);
|