02만료 값 구분자 전환 — 만료 월과 연도의 자릿수 값이 채워지면 그 사이 구분자 값이 자동으로 나타나는 방식
월의 자릿수 값이 두 자리를 채우는 순간 그 뒤 구분자 값이 자동으로 나타나 연도 입력으로 넘어갑니다.
쓰임결제 폼의 카드 유효기간 입력, 정기결제 등록 화면
buildpulsedigitsOnly

<main class="stage">
<div class="ce is-demo" id="ce">
<label class="ce__field">
<input class="ce__input" id="ceInput" type="text" inputmode="numeric" autocomplete="off" spellcheck="false" maxlength="5" value="" placeholder="MM/YY">
</label>
<div class="ce__chips" id="ceChips" aria-hidden="true">
<span class="ce__chip" id="ceMm">MM</span>
<span class="ce__slash" id="ceSlash">/</span>
<span class="ce__chip" id="ceYy">YY</span>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹: 월 값을 01~12 로 clamp 하고, 완료 시 구분자 값을 자동 삽입한다(index.html).
@include stage($stage-yellow);
.ce {
width: 100%;
max-width: 280px;
display: grid;
gap: $sp-4;
justify-items: center;
}
.ce__field { display: block; width: 100%; }
.ce__input {
width: 100%;
box-sizing: border-box;
padding: $sp-3 $sp-4;
border-radius: $r-control;
border: 0;
background: $subject-ink;
color: $subject-cream;
font-weight: 600;
font-size: 18px;
line-height: 1.3;
font-family: "SFMono-Regular", Consolas, monospace;
letter-spacing: .08em;
text-align: center;
&::placeholder { color: rgba($subject-cream, .5); }
&:focus { outline: 2px solid $subject-blue-deep; outline-offset: 2px; }
}
.ce__chips {
display: flex;
align-items: center;
gap: $sp-2;
}
.ce__chip {
min-width: 56px;
box-sizing: border-box;
padding: $sp-2 $sp-3;
border-radius: $r-sm;
background: $subject-cream;
color: rgba($subject-ink, .4);
font-weight: 700;
font-size: 15px;
text-align: center;
transition: color $dur-quick $ease-out;
}
.ce__chip--on { color: $subject-ink; }
.ce__chip--pulse { animation: cePulse $dur-enter $ease-elastic; }
.ce__slash {
font-weight: 700;
font-size: 18px;
color: rgba($subject-ink, .35);
transform: scale(.4);
opacity: 0;
transition: transform $dur-quick $ease-elastic, opacity $dur-quick $ease-out;
}
.ce__slash--on {
transform: scale(1);
opacity: 1;
color: $subject-ink;
}
@keyframes cePulse {
0% { transform: scale(1); }
30% { transform: scale(1.16); }
60% { transform: scale(.96); }
100% { transform: scale(1); }
}
@media (max-width: 340px) {
.ce { max-width: 240px; }
.ce__input { padding: $sp-2 $sp-3; font-size: 16px; }
.ce__chip { min-width: 48px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
.ce__slash { transition: none; }
.ce__chip--pulse { animation: none; }
.ce__chip { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ce {
width: 100%;
max-width: 280px;
display: grid;
gap: 16px;
justify-items: center;
}
.ce__field {
display: block;
width: 100%;
}
.ce__input {
width: 100%;
box-sizing: border-box;
padding: 12px 16px;
border-radius: 12px;
border: 0;
background: #17141a;
color: #fff7e6;
font-weight: 600;
font-size: 18px;
line-height: 1.3;
font-family: "SFMono-Regular", Consolas, monospace;
letter-spacing: 0.08em;
text-align: center;
}
.ce__input::placeholder {
color: rgba(255, 247, 230, 0.5);
}
.ce__input:focus {
outline: 2px solid #0a4fe8;
outline-offset: 2px;
}
.ce__chips {
display: flex;
align-items: center;
gap: 8px;
}
.ce__chip {
min-width: 56px;
box-sizing: border-box;
padding: 8px 12px;
border-radius: 8px;
background: #fff7e6;
color: rgba(23, 20, 26, 0.4);
font-weight: 700;
font-size: 15px;
text-align: center;
transition: color 220ms ease-out;
}
.ce__chip--on {
color: #17141a;
}
.ce__chip--pulse {
animation: cePulse 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ce__slash {
font-weight: 700;
font-size: 18px;
color: rgba(23, 20, 26, 0.35);
transform: scale(0.4);
opacity: 0;
transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 220ms ease-out;
}
.ce__slash--on {
transform: scale(1);
opacity: 1;
color: #17141a;
}
@keyframes cePulse {
0% {
transform: scale(1);
}
30% {
transform: scale(1.16);
}
60% {
transform: scale(0.96);
}
100% {
transform: scale(1);
}
}
@media (max-width: 340px) {
.ce {
max-width: 240px;
}
.ce__input {
padding: 8px 12px;
font-size: 16px;
}
.ce__chip {
min-width: 48px;
font-size: 13px;
}
}
@media (prefers-reduced-motion: reduce) {
.ce__slash {
transition: none;
}
.ce__chip--pulse {
animation: none;
}
.ce__chip {
transition: none;
}
}(function () {
var root = document.getElementById('ce');
var input = document.getElementById('ceInput');
var mmChip = document.getElementById('ceMm');
var yyChip = document.getElementById('ceYy');
var slash = document.getElementById('ceSlash');
// 계산 겹: 월 값의 범위를 01~12 로 clamp 하고, 월 자릿수 값이 2자리를 채우면
// 구분자(슬래시) 값을 자동으로 끼운다.
function digitsOnly(str) { return str.replace(/\D/g, '').slice(0, 4); }
function build(rawDigits) {
var mm = rawDigits.slice(0, 2);
var yy = rawDigits.slice(2, 4);
var clamped = false;
if (mm.length === 2) {
var n = parseInt(mm, 10);
if (n === 0) { mm = '01'; clamped = true; }
else if (n > 12) { mm = '12'; clamped = true; }
}
var slashOn = mm.length === 2;
return { display: mm + (slashOn ? '/' : '') + yy, mm: mm, yy: yy, slashOn: slashOn, clamped: clamped };
}
function pulse(el) {
el.classList.remove('ce__chip--pulse');
void el.offsetWidth;
el.classList.add('ce__chip--pulse');
}
function paint(r) {
mmChip.textContent = r.mm || 'MM';
mmChip.classList.toggle('ce__chip--on', r.mm.length > 0);
yyChip.textContent = r.yy || 'YY';
yyChip.classList.toggle('ce__chip--on', r.yy.length > 0);
slash.classList.toggle('ce__slash--on', r.slashOn);
if (r.clamped) pulse(mmChip);
}
function digitsBefore(str, upto) { return str.slice(0, upto).replace(/\D/g, '').length; }
input.addEventListener('input', function () {
root.classList.remove('is-demo');
stopAutoplay();
var prevDigits = digitsBefore(input.value, input.selectionStart);
var rawDigits = digitsOnly(input.value);
var r = build(rawDigits);
input.value = r.display;
var newCaret = Math.min(prevDigits + (r.slashOn && prevDigits >= 2 ? 1 : 0), input.value.length);
input.setSelectionRange(newCaret, newCaret);
paint(r);
});
// 자동 루프: 시드 고정 자릿수 값 — "13" 을 쳐서 월 범위 clamp("12")가 걸리는 장면 포함.
var SEQ = ['', '1', '13', '132', '1329', '132', '13', '1', ''];
var si = 0;
var autoTimer = null;
function autoTick() {
var rawDigits = SEQ[si];
var r = build(rawDigits);
input.value = r.display;
paint(r);
si = (si + 1) % SEQ.length;
}
function stopAutoplay() { if (autoTimer) { clearInterval(autoTimer); autoTimer = null; } }
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!reduce) { autoTimer = setInterval(autoTick, 340); autoTick(); }
else { autoTick(); }
})();import { useEffect, useRef } from "react";
import styles from "./ExpiryAutoSlash.module.scss";
type Box<T> = { current: T };
type Built = { display: string; mm: string; yy: string; slashOn: boolean; clamped: boolean };
export default function ExpiryAutoSlash() {
const rootRef = useRef(null) as unknown as Box<HTMLDivElement | null>;
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const input = root.querySelector(`.${styles.input}`) as HTMLInputElement | null;
const mmChip = root.querySelector(`.${styles.mm}`) as HTMLElement | null;
const yyChip = root.querySelector(`.${styles.yy}`) as HTMLElement | null;
const slash = root.querySelector(`.${styles.slash}`) as HTMLElement | null;
if (!input || !mmChip || !yyChip || !slash) return;
// 계산 겹: 월 값의 범위를 01~12 로 clamp 하고, 월 자릿수 값이 2자리를 채우면
// 구분자(슬래시) 값을 자동으로 끼운다.
function digitsOnly(str: string) { return str.replace(/\D/g, "").slice(0, 4); }
function build(rawDigits: string): Built {
let mm = rawDigits.slice(0, 2);
const yy = rawDigits.slice(2, 4);
let clamped = false;
if (mm.length === 2) {
const n = parseInt(mm, 10);
if (n === 0) { mm = "01"; clamped = true; }
else if (n > 12) { mm = "12"; clamped = true; }
}
const slashOn = mm.length === 2;
return { display: mm + (slashOn ? "/" : "") + yy, mm, yy, slashOn, clamped };
}
function pulse(el: HTMLElement) {
el.classList.remove(styles["chip--pulse"]);
void el.offsetWidth;
el.classList.add(styles["chip--pulse"]);
}
function paint(r: Built) {
mmChip!.textContent = r.mm || "MM";
mmChip!.classList.toggle(styles["chip--on"], r.mm.length > 0);
yyChip!.textContent = r.yy || "YY";
yyChip!.classList.toggle(styles["chip--on"], r.yy.length > 0);
slash!.classList.toggle(styles["slash--on"], r.slashOn);
if (r.clamped) pulse(mmChip!);
}
function digitsBefore(str: string, upto: number) {
return str.slice(0, upto).replace(/\D/g, "").length;
}
function onInput() {
root!.classList.remove(styles["is-demo"]);
stopAutoplay();
const prevDigits = digitsBefore(input!.value, input!.selectionStart || 0);
const rawDigits = digitsOnly(input!.value);
const r = build(rawDigits);
input!.value = r.display;
const newCaret = Math.min(prevDigits + (r.slashOn && prevDigits >= 2 ? 1 : 0), input!.value.length);
input!.setSelectionRange(newCaret, newCaret);
paint(r);
}
input.addEventListener("input", onInput);
// 자동 루프: 시드 고정 자릿수 값 — "13" 을 쳐서 월 범위 clamp("12")가 걸리는 장면 포함.
const SEQ = ["", "1", "13", "132", "1329", "132", "13", "1", ""];
let si = 0;
let autoTimer: number | null = null;
function autoTick() {
const rawDigits = SEQ[si];
const r = build(rawDigits);
input!.value = r.display;
paint(r);
si = (si + 1) % SEQ.length;
}
function stopAutoplay() {
if (autoTimer !== null) { window.clearInterval(autoTimer); autoTimer = null; }
}
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reduce) { autoTimer = window.setInterval(autoTick, 340); autoTick(); }
else { autoTick(); }
return () => {
stopAutoplay();
input.removeEventListener("input", onInput);
};
}, []);
return (
<div ref={rootRef} className={`${styles.stage} ${styles.ce} ${styles["is-demo"]}`}>
<label className={styles.field}>
<input className={styles.input} type="text" inputMode="numeric" autoComplete="off" spellCheck={false} maxLength={5} defaultValue="" placeholder="MM/YY" />
</label>
<div className={styles.chips} aria-hidden="true">
<span className={`${styles.chip} ${styles.mm}`}>MM</span>
<span className={styles.slash}>/</span>
<span className={`${styles.chip} ${styles.yy}`}>YY</span>
</div>
</div>
);
}02 만료 값 구분자 전환 — 만료 월과 연도의 자릿수 값이 채워지면 그 사이 구분자 값이 자동으로 나타나는 방식 — 측정 누적면적 1.644% · 움직인 프레임 21/23GODRICH 원작 · zip 에 SCSS·React 포함 · 카드 번호 입력 UI 9종 — 자릿수 값마다 반응이 달라지는 아홉 가지 방식
이 데모가 속한 글
카드 번호 입력 UI 9종 — 자릿수 값마다 반응이 달라지는 아홉 가지 방식카드 번호 입력 ui는 자릿수 값이 채워지는 상태에 따라 화면 여러 곳의 값이 함께 바뀌는 인터랙션인데, 아홉 개 중 하나는 입력된 숫자 값이 네 자리에 이를 때마다 그 사이 간격 값이 자동으로 생기고, 하나는 자릿 이 글의 데모 전부 보기
이 효과가 마음에 들면 — 비슷한 데모
입력 UI08 단위 플립 전환 — 단위가 바뀐 상태가 되면 카드가 뒤집히며 90도 지점에서 표시 값이 바뀌는 스텝퍼숫자 스텝퍼 UI 패턴 9종 — 길게 누를수록 빨라지는 것부터 눈금에 붙는 것까지
입력 UI02 문자 종류 수 채움 — 입력 값 안에 섞인 서로 다른 문자 종류 값의 개수에 따라 강도 값이 정해지는 방식비밀번호 강도 UI 9종 — 강도 값이 계산되는 아홉 가지 방식
입력 UI09 모션 축소 대응 비교 전환 — 같은 체크 값 변화를 일반 판은 선 길이 값을 그려서, 축소 판은 중간 단계 없이 바로 보여주는 방식커스텀 체크박스 9종 — 체크 값으로 바뀌는 아홉 가지 방식