-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Button): added Button.Leading, Button.Trailing, and Button.Icon
docs(button): updated examples
- Loading branch information
Showing
5 changed files
with
163 additions
and
46 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,46 @@ | ||
<script lang="ts"> | ||
import { BUTTON_CONTEXT_ID } from './Button.svelte'; | ||
import { useContext } from '../../utils/useContext'; | ||
import { getContext } from 'svelte/internal'; | ||
import { get_current_component } from 'svelte/internal'; | ||
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions'; | ||
export let use: ActionArray = []; | ||
import { exclude } from '../../utils/exclude'; | ||
const forwardEvents = forwardEventsBuilder(get_current_component()); | ||
const { iconSize }: { iconSize: string } = getContext(BUTTON_CONTEXT_ID); | ||
export let data = ''; | ||
export let viewBox = extractViewBox(data); | ||
export let size = iconSize; | ||
export let width = size; | ||
export let height = size; | ||
export let color = 'currentColor'; | ||
export let stroke = color; | ||
export let fill = color; | ||
$: elements = data.replace(/<svg ([^>]*)>/, '').replace('</svg>', ''); | ||
function extractViewBox(svg: string) { | ||
const regex = /viewBox="([\d\- ]+)"/; | ||
const res = regex.exec(svg); | ||
if (!res) return '0 0 24 24'; // default value | ||
return res[1]; | ||
} | ||
</script> | ||
|
||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
{width} | ||
{height} | ||
{viewBox} | ||
{stroke} | ||
{fill} | ||
use:useActions={use} | ||
use:forwardEvents | ||
{...exclude($$props, ['use', 'fill', 'viewBox', 'width', 'height', 'stroke'])} | ||
> | ||
{@html elements} | ||
</svg> |
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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import OriginalButton from './Button.svelte'; | ||
import Loader from './Loader.svelte'; | ||
import Icon from './Icon.svelte'; | ||
|
||
const Button = OriginalButton as ButtonStatic; | ||
Button.Loader = Loader; | ||
Button.Icon = Icon; | ||
Button.Leading = Icon; | ||
Button.Trailing = Icon; | ||
|
||
export default Button; | ||
|
||
export interface ButtonStatic { | ||
new (...args: ConstructorParameters<typeof OriginalButton>): OriginalButton; | ||
Loader: typeof Loader; | ||
Icon: typeof Icon; | ||
Leading: typeof Icon; | ||
Trailing: typeof Icon; | ||
} |
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