2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<button
|
|
|
|
v-if="!link"
|
|
|
|
class="bghgjjyj _button"
|
|
|
|
:class="{ inline, primary, gradate, danger, rounded, full }"
|
|
|
|
:type="type"
|
|
|
|
@click="emit('click', $event)"
|
|
|
|
@mousedown="onMousedown"
|
|
|
|
>
|
|
|
|
<div ref="ripples" class="ripples"></div>
|
|
|
|
<div class="content">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
<MkA
|
|
|
|
v-else
|
|
|
|
class="bghgjjyj _button"
|
|
|
|
:class="{ inline, primary, gradate, danger, rounded, full }"
|
|
|
|
:to="to"
|
|
|
|
@mousedown="onMousedown"
|
|
|
|
>
|
|
|
|
<div ref="ripples" class="ripples"></div>
|
|
|
|
<div class="content">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</MkA>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { nextTick, onMounted } from "vue";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
const props = defineProps<{
|
2023-04-08 02:01:42 +02:00
|
|
|
type?: "button" | "submit" | "reset";
|
2022-09-06 10:37:58 +02:00
|
|
|
primary?: boolean;
|
|
|
|
gradate?: boolean;
|
|
|
|
rounded?: boolean;
|
|
|
|
inline?: boolean;
|
|
|
|
link?: boolean;
|
|
|
|
to?: string;
|
|
|
|
autofocus?: boolean;
|
|
|
|
wait?: boolean;
|
|
|
|
danger?: boolean;
|
|
|
|
full?: boolean;
|
|
|
|
}>();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "click", payload: MouseEvent): void;
|
2022-09-06 10:37:58 +02:00
|
|
|
}>();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
let el = $ref<HTMLElement | null>(null);
|
|
|
|
let ripples = $ref<HTMLElement | null>(null);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
onMounted(() => {
|
|
|
|
if (props.autofocus) {
|
|
|
|
nextTick(() => {
|
|
|
|
el!.focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
function distance(p, q): number {
|
|
|
|
return Math.hypot(p.x - q.x, p.y - q.y);
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
function calcCircleScale(boxW, boxH, circleCenterX, circleCenterY): number {
|
|
|
|
const origin = { x: circleCenterX, y: circleCenterY };
|
|
|
|
const dist1 = distance({ x: 0, y: 0 }, origin);
|
|
|
|
const dist2 = distance({ x: boxW, y: 0 }, origin);
|
|
|
|
const dist3 = distance({ x: 0, y: boxH }, origin);
|
|
|
|
const dist4 = distance({ x: boxW, y: boxH }, origin);
|
|
|
|
return Math.max(dist1, dist2, dist3, dist4) * 2;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-06 10:37:58 +02:00
|
|
|
function onMousedown(evt: MouseEvent): void {
|
|
|
|
const target = evt.target! as HTMLElement;
|
|
|
|
const rect = target.getBoundingClientRect();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const ripple = document.createElement("div");
|
|
|
|
ripple.style.top = (evt.clientY - rect.top - 1).toString() + "px";
|
|
|
|
ripple.style.left = (evt.clientX - rect.left - 1).toString() + "px";
|
2022-09-06 10:37:58 +02:00
|
|
|
|
|
|
|
ripples!.appendChild(ripple);
|
|
|
|
|
|
|
|
const circleCenterX = evt.clientX - rect.left;
|
|
|
|
const circleCenterY = evt.clientY - rect.top;
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const scale = calcCircleScale(
|
|
|
|
target.clientWidth,
|
|
|
|
target.clientHeight,
|
|
|
|
circleCenterX,
|
|
|
|
circleCenterY
|
|
|
|
);
|
2022-09-06 10:37:58 +02:00
|
|
|
|
|
|
|
window.setTimeout(() => {
|
2023-04-08 02:01:42 +02:00
|
|
|
ripple.style.transform = "scale(" + scale / 2 + ")";
|
2022-09-06 10:37:58 +02:00
|
|
|
}, 1);
|
|
|
|
window.setTimeout(() => {
|
2023-04-08 02:01:42 +02:00
|
|
|
ripple.style.transition = "all 1s ease";
|
|
|
|
ripple.style.opacity = "0";
|
2022-09-06 10:37:58 +02:00
|
|
|
}, 1000);
|
|
|
|
window.setTimeout(() => {
|
|
|
|
if (ripples) ripples.removeChild(ripple);
|
|
|
|
}, 2000);
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.bghgjjyj {
|
|
|
|
position: relative;
|
2020-10-17 13:12:00 +02:00
|
|
|
z-index: 1; // 他コンポーネントのbox-shadowに隠されないようにするため
|
2020-01-29 20:37:25 +01:00
|
|
|
display: block;
|
|
|
|
min-width: 100px;
|
2021-08-08 05:19:10 +02:00
|
|
|
width: max-content;
|
2022-07-24 08:41:06 +02:00
|
|
|
padding: 8px 16px;
|
2020-01-29 20:37:25 +01:00
|
|
|
text-align: center;
|
|
|
|
font-weight: normal;
|
2022-07-16 13:53:53 +02:00
|
|
|
font-size: 1em;
|
2020-01-29 20:37:25 +01:00
|
|
|
box-shadow: none;
|
|
|
|
text-decoration: none;
|
|
|
|
background: var(--buttonBg);
|
2021-11-28 12:07:37 +01:00
|
|
|
border-radius: 5px;
|
2022-07-13 14:41:06 +02:00
|
|
|
overflow: clip;
|
2021-08-07 10:55:16 +02:00
|
|
|
box-sizing: border-box;
|
2021-08-09 11:01:12 +02:00
|
|
|
transition: background 0.1s ease;
|
2022-07-24 08:54:54 +02:00
|
|
|
margin-right: 0.2rem;
|
|
|
|
margin-left: 0.2rem;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
|
|
|
background: var(--buttonHoverBg);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):active {
|
|
|
|
background: var(--buttonHoverBg);
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.full {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2021-10-02 19:46:58 +02:00
|
|
|
&.rounded {
|
|
|
|
border-radius: 999px;
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
&.primary {
|
2021-04-24 15:38:24 +02:00
|
|
|
font-weight: bold;
|
2021-08-08 14:59:18 +02:00
|
|
|
color: var(--fgOnAccent) !important;
|
2020-01-29 20:37:25 +01:00
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
2021-10-13 18:27:45 +02:00
|
|
|
background: var(--X8);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):active {
|
|
|
|
background: var(--X8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.gradate {
|
|
|
|
font-weight: bold;
|
|
|
|
color: var(--fgOnAccent) !important;
|
2023-04-08 02:01:42 +02:00
|
|
|
background: linear-gradient(
|
|
|
|
90deg,
|
|
|
|
var(--buttonGradateA),
|
|
|
|
var(--buttonGradateB)
|
|
|
|
);
|
2021-10-13 18:27:45 +02:00
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
2021-10-16 08:00:55 +02:00
|
|
|
background: linear-gradient(90deg, var(--X8), var(--X8));
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):active {
|
2021-10-16 08:00:55 +02:00
|
|
|
background: linear-gradient(90deg, var(--X8), var(--X8));
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.danger {
|
2022-07-24 08:46:13 +02:00
|
|
|
color: #eb6f92;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
&.primary {
|
2022-07-24 08:46:13 +02:00
|
|
|
color: #e0def4;
|
|
|
|
background: #eb6f92;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
2022-07-24 08:46:13 +02:00
|
|
|
background: #eb6f92;
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):active {
|
2022-07-24 08:46:13 +02:00
|
|
|
background: #b4637a;
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
&:disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
2021-10-02 19:46:58 +02:00
|
|
|
&:focus-visible {
|
2023-04-30 00:30:14 +02:00
|
|
|
outline: auto;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
&.inline {
|
|
|
|
display: inline-block;
|
|
|
|
width: auto;
|
|
|
|
min-width: 100px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .ripples {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 0;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 6px;
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
::v-deep(div) {
|
2020-01-29 20:37:25 +01:00
|
|
|
position: absolute;
|
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
border-radius: 100%;
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
|
|
|
opacity: 1;
|
|
|
|
transform: scale(1);
|
2023-04-08 02:01:42 +02:00
|
|
|
transition: all 0.5s cubic-bezier(0, 0.5, 0, 1);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.primary > .ripples ::v-deep(div) {
|
2020-01-29 20:37:25 +01:00
|
|
|
background: rgba(0, 0, 0, 0.15);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .content {
|
|
|
|
position: relative;
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|