2019-08-19 22:18:23 +02:00
|
|
|
<script>
|
2019-10-07 07:03:41 +02:00
|
|
|
import cssVars from "./cssVars";
|
|
|
|
import {buildStyle} from "./buildStyle";
|
2019-08-27 08:32:56 +02:00
|
|
|
export let className = "default";
|
2019-08-19 22:18:23 +02:00
|
|
|
export let disabled = false;
|
2019-08-27 08:32:56 +02:00
|
|
|
export let contentText;
|
|
|
|
export let contentComponent;
|
2019-10-10 07:18:02 +02:00
|
|
|
export let onClick;
|
2019-10-07 07:03:41 +02:00
|
|
|
export let background;
|
|
|
|
export let color;
|
|
|
|
export let border;
|
|
|
|
export let padding;
|
|
|
|
export let hoverColor;
|
|
|
|
export let hoverBackground;
|
|
|
|
export let hoverBorder;
|
2019-08-27 08:32:56 +02:00
|
|
|
|
2019-09-27 18:03:31 +02:00
|
|
|
export let _bb;
|
2019-09-03 11:42:19 +02:00
|
|
|
let contentComponentContainer;
|
2019-10-07 07:03:41 +02:00
|
|
|
let cssVariables;
|
|
|
|
let buttonStyles;
|
|
|
|
|
|
|
|
let customHoverColorClass;
|
|
|
|
let customHoverBorderClass;
|
|
|
|
let customHoverBackClass;
|
2019-09-03 11:42:19 +02:00
|
|
|
|
2019-10-10 11:41:31 +02:00
|
|
|
let customClasses = "";
|
|
|
|
|
|
|
|
const createClasses = (classes) => {
|
|
|
|
let all = "";
|
|
|
|
for(let cls in classes) {
|
|
|
|
if(classes[cls]) {
|
|
|
|
all = all + " " + cls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-03 11:42:19 +02:00
|
|
|
$:{
|
2019-09-27 18:03:31 +02:00
|
|
|
if(_bb && contentComponentContainer && contentComponent._component)
|
2020-01-18 00:06:42 +01:00
|
|
|
_bb.hydrateChildren(_bb.props.contentComponent, contentComponentContainer);
|
2019-10-07 07:03:41 +02:00
|
|
|
|
|
|
|
cssVariables = {
|
|
|
|
hoverColor, hoverBorder,
|
2019-10-10 11:41:31 +02:00
|
|
|
hoverBackground,
|
|
|
|
background, color, border,
|
2019-10-07 07:03:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
buttonStyles = buildStyle({
|
2019-10-10 11:41:31 +02:00
|
|
|
padding
|
|
|
|
});
|
|
|
|
|
|
|
|
customClasses = createClasses({
|
|
|
|
hoverColor, hoverBorder, hoverBackground,
|
|
|
|
background, border, color
|
|
|
|
});
|
|
|
|
|
2019-09-03 11:42:19 +02:00
|
|
|
}
|
|
|
|
|
2019-09-22 06:02:33 +02:00
|
|
|
|
2019-10-07 07:03:41 +02:00
|
|
|
|
|
|
|
|
2019-09-22 06:02:33 +02:00
|
|
|
const clickHandler = () => {
|
2019-10-07 07:03:41 +02:00
|
|
|
_bb.call(onClick);
|
2019-09-22 06:02:33 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 22:18:23 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
2019-10-07 07:03:41 +02:00
|
|
|
<button use:cssVars={cssVariables}
|
2019-10-10 11:41:31 +02:00
|
|
|
class="{className} {customClasses}"
|
2019-10-10 07:18:02 +02:00
|
|
|
disabled={disabled || false}
|
2019-10-07 07:03:41 +02:00
|
|
|
on:click={clickHandler}
|
|
|
|
style={buttonStyles}>
|
2019-08-27 08:32:56 +02:00
|
|
|
{#if contentComponent && contentComponent._component}
|
2019-09-03 11:42:19 +02:00
|
|
|
<div bind:this={contentComponentContainer}>
|
|
|
|
</div>
|
2019-08-27 08:32:56 +02:00
|
|
|
{:else if contentText}
|
2019-08-19 22:18:23 +02:00
|
|
|
{contentText}
|
|
|
|
{:else}
|
2019-08-27 08:32:56 +02:00
|
|
|
<slot />
|
2019-08-19 22:18:23 +02:00
|
|
|
{/if}
|
2019-08-27 08:32:56 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
.default {
|
|
|
|
font-family: inherit;
|
|
|
|
font-size: inherit;
|
|
|
|
padding: 0.4em;
|
|
|
|
margin: 0 0 0.5em 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 2px;
|
|
|
|
color: #333;
|
|
|
|
background-color: #f4f4f4;
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.default:active {
|
|
|
|
background-color: #ddd;
|
|
|
|
}
|
|
|
|
|
|
|
|
.default:focus {
|
|
|
|
border-color: #666;
|
|
|
|
}
|
|
|
|
|
2019-10-10 11:41:31 +02:00
|
|
|
.border {
|
|
|
|
border: var(--border);
|
|
|
|
}
|
|
|
|
|
|
|
|
.color {
|
|
|
|
color: var(--color);
|
|
|
|
}
|
|
|
|
|
|
|
|
.background {
|
|
|
|
background: var(--background);
|
|
|
|
}
|
|
|
|
|
|
|
|
.hoverBorder:hover {
|
2019-10-07 07:03:41 +02:00
|
|
|
border: var(--hoverBorder);
|
|
|
|
}
|
|
|
|
|
2019-10-10 11:41:31 +02:00
|
|
|
.hoverColor:hover {
|
2019-10-07 07:03:41 +02:00
|
|
|
color: var(--hoverColor);
|
|
|
|
}
|
|
|
|
|
2019-10-10 11:41:31 +02:00
|
|
|
.hoverBack:hover {
|
2019-10-07 07:03:41 +02:00
|
|
|
background: var(--hoverBackground);
|
|
|
|
}
|
2019-10-10 11:41:31 +02:00
|
|
|
|
|
|
|
|
2019-08-27 08:32:56 +02:00
|
|
|
</style>
|