Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioButtonとRadioCardの実装 #57

Merged
merged 20 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="@/main.ts"></script>
<script type="module" src="./src/main.ts"></script>
cp-20 marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
41 changes: 41 additions & 0 deletions src/pages/registerView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<div :class="$style.wrapper">
<div :class="$style.container">
<div :class="$style.itemA">A</div>
<div :class="$style.itemB">B</div>
<div :class="$style.itemC">C</div>
</div>
</div>
</template>

<script setup lang="ts"></script>

<style lang="scss" module>
.wrapper {
display: flex;
justify-content: center;
padding: 50px 0;
}

.container {
display: grid;
width: 1024px;
padding: 32px;
grid-template-rows: 200px 120px;
grid-template-columns: 160px 160px 160px 160px 160px 160px;
border: 1px solid red;
}
.itemA {
border: 1px solid orange;
grid-column: 1 / span 3;
}
.itemB {
border: 1px solid blue;
grid-column: 4 / span 3;
}
.itemC {
border: 1px solid green;
grid-column: 1 / span 2;
padding-top: 32px;
}
</style>
6 changes: 6 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import registerView from '@/pages/registerView.vue';

export const routerHistory = createWebHistory();

Expand All @@ -9,6 +10,11 @@ const routes: RouteRecordRaw[] = [
name: 'Dashboard',
component: () => import('@/pages/DashBoard.vue'),
},
{
path: '/register',
name: 'register',
component: registerView,
},
];

export default createRouter({
Expand Down
75 changes: 75 additions & 0 deletions src/shared/components/RadioButton.vue
cp-20 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<input
:id="props.inputId"
:class="$style.input"
type="radio"
:name="props.name"
:value="props.value"
@change="model = props.value"
/>
<label
:for="props.inputId"
:class="$style.label"
:style="`width: ${props.size}; height: ${props.size}`"
>
</label>
</template>

<script lang="ts" setup>
const props = withDefaults(
defineProps<{
inputId: string;
name: string;
value: string;
size?: string;
}>(),
{
size: '24px',
},
);

const model = defineModel<string>();
</script>

<style lang="scss" module>
.input {
display: none;
}

.label {
display: inline-block;
cursor: pointer;
position: relative;
}

.label::before {
content: '';
width: 100%;
height: 100%;
border-radius: 50%;
background-color: $color-container-secondary;
border: 2px solid $color-secondary;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
z-index: 10;
box-sizing: border-box;
}

.input:checked + .label::before {
background-color: $color-primary;
border: none;
}

.input:checked + .label::after {
content: '';
width: 50%;
height: 50%;
border-radius: 50%;
background-color: $color-background;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
z-index: 11;
}
</style>
132 changes: 132 additions & 0 deletions src/shared/components/RadioCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<template>
<input
:id="props.inputId"
:class="$style.input"
type="radio"
:name="props.name"
:value="props.value"
@change="model = props.value"
/>
<label
:class="$style.container"
:style="`width: ${props.width}`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<style>タグ内で v-bindを使った方がシンプルに書けると思います:eyes:
https://azukiazusa.dev/blog/vue3-2-style-javascript/

:for="props.inputId"
>
<div :class="$style.title_wrapper">
<div :class="$style.title">{{ props.title }}</div>
<div :class="$style.btn"></div>
cp-20 marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div :class="$style.content">
{{ props.content }}
</div>
</label>
</template>

<script lang="ts" setup>
const props = withDefaults(
defineProps<{
title: string;
content: string;
inputId: string;
cp-20 marked this conversation as resolved.
Show resolved Hide resolved
name: string;
value: string;
width?: string;
height?: string;
}>(),
{
width: '310px',
},
cp-20 marked this conversation as resolved.
Show resolved Hide resolved
);

const model = defineModel<string>();
</script>

<style lang="scss" module>
.container {
box-shadow: inset 0 0 0 1px $color-secondary;
border-radius: 4px;
display: flex;
width: 351px;
padding: 16px;
flex-direction: column;
align-items: flex-start;
gap: 8px;
cursor: pointer;
}

.container:hover {
background-color: $color-primary-hover;
}

.input:checked + .container {
box-shadow: inset 0 0 0 3px $color-primary;
}

.title_wrapper {
display: flex;
justify-content: space-between;
align-items: center;
align-self: stretch;
}

.title {
color: $color-text-primary;
font-size: 16px;
font-style: normal;
font-weight: 700;
line-height: normal;
}

.content {
font-size: 16px;
text-align: left;
align-self: stretch;
color: $color-text-dimmed;
font-size: 16px;
font-weight: 500;
line-height: normal;
}

.input {
display: none;
}

.btn {
cursor: pointer;
position: relative;
width: 24px;
height: 24px;
flex-shrink: 0;
}

.btn::before {
content: '';
width: 100%;
height: 100%;
border-radius: 50%;
background-color: $color-container-secondary;
border: 2px solid $color-secondary;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
z-index: 10;
box-sizing: border-box;
}

.input:checked + .container .title_wrapper .btn::before {
background-color: $color-primary;
border: none;
}

.input:checked + .container .title_wrapper .btn::after {
content: '';
width: 50%;
height: 50%;
border-radius: 50%;
background-color: $color-background;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
z-index: 11;
}
</style>
7 changes: 5 additions & 2 deletions src/styles/common.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use 'sass:math';

$color-primary: #5cb860;
$color-primary-hover: #7fc782;
$color-primary-hover: #eef7ee;
$color-primary-disabled: #a9d0ab;

$color-secondary: #e2e2e2;
Expand All @@ -10,12 +10,15 @@ $color-secondary-disabled: #c9cac9;

$color-error: #ff4500;

$color-text-primary: #2b2b2b;
$color-text-primary: #1a1a1c;
$color-text-primary-disabled: #7a7a7a;
$color-text-secondary: #515151;
$color-text-secondary-pale: #5151515d;
$color-text-secondary-disabled: #939393;
$color-text-white: #ffffff;
$color-text-dimmed: #626264;

$color-container-secondary: #f1f1f4;

$color-background: #ffffff;
$color-background-dim: #2b2b2baa;
Expand Down
Loading