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