08종횡비 크롭 프리셋 피커
1:1·4:5·16:9·9:16 칩 중 하나를 고르면 미리보기 박스의 aspect-ratio 값이 그 비율로 부드럽게 바뀐다.
쓰임프로필 사진 크롭 비율 선택, 릴스·쇼츠 업로드 비율 고르기
aspect-ratio 전환role=radiogroup0.3초

<main class="stage">
<div class="ar is-demo">
<div class="ar__preview"><div class="ar__box" id="box"></div></div>
<div class="ar__chips" role="radiogroup" aria-label="종횡비 선택">
<label class="ar__chip"><input type="radio" name="ar" class="ar__radio" value="1/1" checked><span>1:1</span></label>
<label class="ar__chip"><input type="radio" name="ar" class="ar__radio" value="4/5"><span>4:5</span></label>
<label class="ar__chip"><input type="radio" name="ar" class="ar__radio" value="16/9"><span>16:9</span></label>
<label class="ar__chip"><input type="radio" name="ar" class="ar__radio" value="9/16"><span>9:16</span></label>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────
$duration: $dur-base;
$easing: $ease-spring;
$color: $stage-orange;
@include stage($stage-paper);
.ar { display: flex; flex-direction: column; align-items: center; gap: $sp-2; }
.ar__preview { height: 96px; display: grid; place-items: center; width: 100%; }
.ar__box {
aspect-ratio: 1 / 1; height: 100%; max-width: 90%;
border-radius: $r-sm; background: rgba($color, .16); border: 2px solid $color;
transition: aspect-ratio $duration $easing;
}
.ar__chips { display: flex; gap: $sp-2; }
.ar__chip { position: relative; }
.ar__radio { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ar__chip span {
display: grid; place-items: center; padding: $sp-2 $sp-3; border-radius: $r-pill;
border: 1px solid rgba($subject-ink, .18); font-size: 12px; font-weight: 700; color: $subject-ink;
cursor: pointer; transition: background-color $duration $easing, color $duration $easing, transform $duration $easing;
}
.ar__radio:checked ~ span { background: $color; border-color: $color; color: #fff; transform: scale(1.05); }
.ar__radio:focus-visible ~ span { outline: 2px solid $subject-ink; outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
.ar__box, .ar__chip span { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ar {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.ar__preview {
height: 96px;
display: grid;
place-items: center;
width: 100%;
}
.ar__box {
aspect-ratio: 1/1;
height: 100%;
max-width: 90%;
border-radius: 8px;
background: rgba(255, 77, 31, 0.16);
border: 2px solid #ff4d1f;
transition: aspect-ratio 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ar__chips {
display: flex;
gap: 8px;
}
.ar__chip {
position: relative;
}
.ar__radio {
position: absolute;
opacity: 0;
width: 1px;
height: 1px;
}
.ar__chip span {
display: grid;
place-items: center;
padding: 8px 12px;
border-radius: 999px;
border: 1px solid rgba(23, 20, 26, 0.18);
font-size: 12px;
font-weight: 700;
color: #17141a;
cursor: pointer;
transition: background-color 300ms cubic-bezier(0.2, 0.8, 0.2, 1), color 300ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ar__radio:checked ~ span {
background: #ff4d1f;
border-color: #ff4d1f;
color: #fff;
transform: scale(1.05);
}
.ar__radio:focus-visible ~ span {
outline: 2px solid #17141a;
outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
.ar__box, .ar__chip span {
transition: none;
}
}(function () {
var ar = document.querySelector('.ar'), box = document.getElementById('box');
var radios = Array.prototype.slice.call(ar.querySelectorAll('.ar__radio'));
function apply(v) { box.style.aspectRatio = v; }
radios.forEach(function (r) { r.addEventListener('change', function () { stop(); apply(r.value); }); });
var seq = ['1/1', '4/5', '16/9', '9/16'], si = 0;
var t = setInterval(function () {
si = (si + 1) % seq.length;
radios[si].checked = true; apply(seq[si]);
}, 700);
function stop() { ar.classList.remove('is-demo'); clearInterval(t); }
apply('1/1');
}());import { useState } from "react";
import type { CSSProperties } from "react";
import styles from "./AspectRatioCropPresetPicker.module.scss";
export type AspectRatioCropPresetPickerProps = {
ratios?: string[];
duration?: number;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--c"?: string };
export default function AspectRatioCropPresetPicker({
ratios = ["1/1", "4/5", "16/9", "9/16"],
duration = 300,
easing = "cubic-bezier(.2,.8,.2,1)",
color = "#ff4d1f",
}: AspectRatioCropPresetPickerProps) {
const [ratio, setRatio] = useState(ratios[0]);
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--c": color };
return (
<div className={styles.ar} style={vars}>
<div className={styles.preview}>
<div className={styles.box} style={{ aspectRatio: ratio }} />
</div>
<div className={styles.chips} role="radiogroup" aria-label="Select aspect ratio">
{ratios.map((r) => (
<label key={r} className={styles.chip}>
<input type="radio" name="ratio" className={styles.radio} checked={ratio === r}
onChange={() => setRatio(r)} />
<span data-on={ratio === r}>{r.replace("/", ":")}</span>
</label>
))}
</div>
</div>
);
}08 종횡비 크롭 프리셋 피커 — 측정 누적면적 12.704% · 움직인 프레임 11/23GODRICH 원작 · zip 에 SCSS·React 포함 · 달력 선택 UI 9종 — 복붙하면 되는
이 데모가 속한 글
달력 선택 UI 9종 — 복붙하면 되는달력 선택 UI는 시작일과 종료일처럼 값 하나가 아니라 범위·묶음을 고르게 해주는 선택 도구입니다. 세그먼트 컨트롤이나 색상 스와치처럼 이미 다뤘던 낱개 선택지 말고, 날짜 범위·가격대·아바타·사이즈+수량·검색 드롭 이 글의 데모 전부 보기


