-
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
- Loading branch information
Showing
8 changed files
with
261 additions
and
26 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
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,52 @@ | ||
# SFragment | ||
|
||
`<SFragment>` is a utility component that allows you to wrap some component with another component based on conditions. | ||
|
||
## Usage | ||
|
||
Import `<SFragment>` component and wrap it around with other component. Specify `:is` prop to define the component to be used. When `:is` prop is not defined, it will render the underlining component directly. | ||
|
||
This component is useful in a case for example you want to wrap some component with `<STooltip>` only when some props are passed. | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import SButton from '@globalbrain/sefirot/lib/components/SButton.vue' | ||
import STooltip from '@globalbrain/sefirot/lib/components/STooltip.vue' | ||
import SButton from '@globalbrain/sefirot/lib/components/SFragment.vue' | ||
const tooltip = ref('') | ||
</script> | ||
<template> | ||
<!-- | ||
Wrap component with `<SToooltip>` only when tooltip ref | ||
is set. Otherwise, it will render `<SButton>` directly. | ||
--> | ||
<SFragment :is="tooltip && STooltip" :text="tooltip"> | ||
<SButton label="Button" /> | ||
</SFragment> | ||
</template> | ||
``` | ||
|
||
Note that `<SFragment>` will pass down all additional props defined along with `:is`, for example in the above case `:text` is passed to `<STooltip>`. | ||
|
||
## Props | ||
|
||
Here are the list of props you may pass to the component. | ||
|
||
### `:is` | ||
|
||
The component to be used to wrap the children. When this prop is not defined, it will render the children directly. | ||
|
||
```ts | ||
interface Props { | ||
is?: any | ||
} | ||
``` | ||
|
||
```vue-html | ||
<SFragment :is="STooltip"> | ||
... | ||
</SFragment> | ||
``` |
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
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,16 @@ | ||
<script lang="ts"> | ||
export default { inheritAttrs: false } | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
defineProps<{ is?: any }>() | ||
</script> | ||
|
||
<template> | ||
<component v-if="is" :is="is" v-bind="$attrs"> | ||
<template v-for="(_, slot) of $slots" #[slot]="scope"> | ||
<slot :name="slot" v-bind="scope" /> | ||
</template> | ||
</component> | ||
<slot v-else /> | ||
</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
Oops, something went wrong.