-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
close #293 --------- Co-authored-by: Kia King Ishii <kia.king.08@gmail.com>
- Loading branch information
1 parent
864c9c5
commit 9179f1d
Showing
5 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# SLink | ||
|
||
`<SLink>` is a styleless component that renders an anchor tag with custom utility options. | ||
|
||
## Usage | ||
|
||
You may use `<SLink>` as almost the same as `<a>` tag. Wrap text with it and it will render an anchor tag with the text inside. | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import SLink from '@globalbrain/sefirot/lib/components/SLink.vue' | ||
</script> | ||
<template> | ||
<SLink href="https://example.com"> | ||
Link text | ||
</SLink> | ||
</template> | ||
``` | ||
|
||
`<SLink>` will automatically add `target="_blank"` and `rel="noopener noreferrer"` to the anchor tag if the `href` prop is an external link. If the link is internal, it will use `<RouterLink>` component from Vue Router instead. | ||
|
||
```vue-html | ||
<SLink href="https://example.com"> | ||
<!-- Becomes --> | ||
<a href="https://example.com" target="_blank" rel="noopener noreferrer"> | ||
<SLink href="/about"> | ||
<!-- Becomes --> | ||
<RouterLink to="/about"> | ||
``` | ||
|
||
You may pass `:external` prop to override this behavior. For example, if you would like to have an internal link open in another tab, set `:external` to `true`. | ||
|
||
```vue-html | ||
<SLink href="/about" external> | ||
<!-- Becomes --> | ||
<a href="/about" target="_blank" rel="noopener noreferrer"> | ||
``` | ||
|
||
## Props | ||
|
||
Here are the list of props you may pass to the component. | ||
|
||
### `:href` | ||
|
||
The link to be used. If the link is external, it will automatically add `target="_blank"` and `rel="noopener noreferrer"` to the anchor tag. | ||
|
||
```ts | ||
interface Props { | ||
href?: string | ||
} | ||
``` | ||
|
||
```vue-html | ||
<SLink href="/about">...</SLink> | ||
``` | ||
|
||
### `:external` | ||
|
||
Override the automatic external link detection. If set to `true`, it will always add `target="_blank"` and `rel="noopener noreferrer"` to the anchor tag. | ||
|
||
```ts | ||
interface Props { | ||
external?: boolean | ||
} | ||
``` | ||
|
||
```vue-html | ||
<SLink href="/about" external>...</SLink> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script setup lang="ts"> | ||
import SLink from 'sefirot/components/SLink.vue' | ||
const title = 'Components / SLink / 01. Playground' | ||
const docs = '/components/link' | ||
function state() { | ||
return { | ||
href: 'https://example.com', | ||
external: 'undefined', | ||
text: 'This is link text' | ||
} as const | ||
} | ||
function getExternal(value: 'undefined' | 'true' | 'false') { | ||
return value === 'undefined' ? undefined : value === 'true' | ||
} | ||
</script> | ||
|
||
<template> | ||
<Story :title="title" :init-state="state" source="Not available" auto-props-disabled> | ||
<template #controls="{ state }"> | ||
<HstText | ||
title="href" | ||
v-model="state.href" | ||
/> | ||
<HstText | ||
title="text" | ||
v-model="state.text" | ||
/> | ||
<HstSelect | ||
title="external" | ||
:options="{ | ||
undefined: 'undefined', | ||
true: 'true', | ||
false: 'false' | ||
}" | ||
v-model="state.external" | ||
/> | ||
</template> | ||
|
||
<template #default="{ state }"> | ||
<Board :title="title" :docs="docs"> | ||
<SLink | ||
:href="state.href" | ||
:external="getExternal(state.external)" | ||
> | ||
{{ state.text }} | ||
</SLink> | ||
</Board> | ||
</template> | ||
</Story> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters