1 звезда на GitHub = 1 новый компонент.

Поставить звезду
Портфолио разработчика

Dev Keyboard 3D

3D-механическая клавиатура во всю ширину, которая сама печатает ваш стек и повторяет каждое слово огромными буквами на фоне; содержимое слота (например, список репозиториев) лежит поверх нижних рядов.

keyboardthree3dtypingportfolio
Живое превью

Использование

Скопируйте и вставьте этот код в ваш React-компонент:

tsx
import { DevKeyboard } from 'react-component-kit-ui/sections';

{/* npm install three */}
<DevKeyboard phrases={['REACT', 'REACT', 'TYPESCRIPT']}>
  <DevRepoList repos={repos} />
</DevKeyboard>

Ручная установка

Если вы не используете пакет npm, создайте файл и вставьте следующий код: src/components/sections/DevKeyboard.tsx + DevKeyboard.css:

DevKeyboard.tsx
'use client';

import { useEffect, useRef } from 'react';
import type { CSSProperties, ReactNode } from 'react';
import './DevKeyboard.css';

/** class:list → className */
function cx(...args: unknown[]): string {
  const out: string[] = [];
  const walk = (v: unknown) => {
    if (!v) return;
    if (typeof v === 'string' || typeof v === 'number') out.push(String(v));
    else if (Array.isArray(v)) v.forEach(walk);
    else if (typeof v === 'object') for (const [k, on] of Object.entries(v as Record<string, unknown>)) if (on) out.push(k);
  };
  args.forEach(walk);
  return out.join(' ');
}

/** "a: b; --c: d" → style object */
function st(css: string | undefined): CSSProperties {
  const o: Record<string, string> = {};
  for (const decl of String(css ?? '').split(';')) {
    const i = decl.indexOf(':');
    if (i < 0) continue;
    const k = decl.slice(0, i).trim();
    if (k) o[k.startsWith('--') ? k : k.replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = decl.slice(i + 1).trim();
  }
  return o as CSSProperties;
}

/**
 * DevKeyboard — Full-width 3D mechanical keyboard ("Keycap" design) that types a list of words by
 * itself and echoes each one as a huge backdrop word. Clicking a key presses it. Anything passed
 * in the default slot floats over the lower part of the keyboard (e.g. a repository list), leaving
 * the top rows visible. Light/dark aware. Needs the optional `three` peer dependency.
 *
 * @param {string[]} phrases - Words typed in a loop.
 * @param {string} reveal - Space kept free above the slot content so the keys show. Default '24rem'.
 * @param {string} minHeight - Height when the slot is empty. Default '560px'.
 * @param {number} speed - Milliseconds per keystroke. Default 140.
 * @param {string} label - Accessible description of the animation. Default 'Animated keyboard typing'.
 * @param {string} className - Extra class.
 *
 * Accessibility: the canvas is decorative (role="img" with a label listing the words); the typed
 * word is aria-hidden; with prefers-reduced-motion the board is static and shows the first word.
 */
export interface DevKeyboardProps {
  phrases?: string[];
  reveal?: string;
  minHeight?: string;
  speed?: number;
  label?: string;
  className?: string;
  children?: ReactNode;
}

export function DevKeyboard({
  phrases = ['REACT', 'NEXT.JS', 'TYPESCRIPT', 'THREE.JS', 'NODE.JS'],
  reveal = '24rem',
  minHeight = '560px',
  speed = 140,
  label = 'Animated keyboard typing',
  className = '',
  children
}: DevKeyboardProps) {
  const hasSlot = (children != null);

  // 3D keyboard: three.js is loaded on demand (optional peer dependency) and disposed on unmount.
  const rootRef = useRef<HTMLElement>(null);
  const phrasesKey = phrases.join('\u0000');
  useEffect(() => {
    const root = rootRef.current;
    const canvas = root?.querySelector<HTMLElement>('[data-canvas]');
    if (!root || !canvas) return;
    let cancelled = false;
    let dispose: (() => void) | undefined;
    Promise.all([import('three'), import('../three/keyboard-scene')])
      .then(([THREE, { mountKeyboard }]) => {
        if (!cancelled) dispose = mountKeyboard(canvas, THREE, { phrases, typedEl: root.querySelector<HTMLElement>('[data-typed]'), speed });
      })
      .catch((err) => console.warn('[DevKeyboard] the 3D keyboard needs the optional `three` peer dependency.', err));
    return () => {
      cancelled = true;
      dispose?.();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [phrasesKey, speed]);
  return (
    <>
      <section ref={rootRef} className={cx(['dvkb', { 'dvkb--empty': !hasSlot }, className])} style={st(`--dvkb-reveal:${reveal};--dvkb-min:${minHeight}`)} data-dev-keyboard data-phrases={JSON.stringify(phrases)} data-speed={speed} data-rk-5cdff8="">
        <div className="dvkb__stage" data-rk-5cdff8="">
          <div className="dvkb__word" aria-hidden="true" data-rk-5cdff8=""><span data-typed data-rk-5cdff8=""></span><span className="dvkb__cursor" data-rk-5cdff8="">_</span></div>
          <div className="dvkb__canvas" data-canvas role="img" aria-label={`${label}: ${phrases.join(', ')}`} data-rk-5cdff8=""></div>
        </div>
        {hasSlot && <div className="dvkb__content" data-rk-5cdff8="">{children}</div>}
      </section>
    </>
  );
}

export default DevKeyboard;
DevKeyboard.css
.dvkb:where([data-rk-5cdff8]) {
  --kc-ink: var(--c-text-1);
  --kc-paper: var(--c-bg);
  --kc-muted: var(--c-text-3);
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--c-bg);
}
.dvkb--empty:where([data-rk-5cdff8]) { min-height: var(--dvkb-min); }
/* The board lives in the top band; slot content overlaps its lower rows. */
.dvkb__stage:where([data-rk-5cdff8]) { position: absolute; inset: 0 0 auto; height: calc(var(--dvkb-reveal) + 18rem); }
.dvkb--empty:where([data-rk-5cdff8]) .dvkb__stage:where([data-rk-5cdff8]) { height: 100%; }
.dvkb__canvas:where([data-rk-5cdff8]) { position: relative; z-index: 1; width: 100%; height: 100%; cursor: pointer; }
.dvkb__word:where([data-rk-5cdff8]) {
  position: absolute;
  top: 15%;
  left: 57%;
  z-index: 0;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: clamp(3.2rem, 9.2vw, 8.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  color: rgb(var(--ink-rgb, 0 0 0) / 0.12);
  pointer-events: none;
  user-select: none;
}
.dvkb__cursor:where([data-rk-5cdff8]) { margin-left: 0.15ch; font-weight: 300; color: rgb(var(--ink-rgb, 0 0 0) / 0.45); animation: dev-keyboard-dvkb-blink 0.85s ease-in-out infinite; }
.dvkb__content:where([data-rk-5cdff8]) {
  position: relative;
  z-index: 2;
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--dvkb-reveal) clamp(1rem, 3vw, 1.5rem) 1.5rem;
  pointer-events: none;
}
.dvkb__content:where([data-rk-5cdff8]) > * { pointer-events: auto; }
@keyframes dev-keyboard-dvkb-blink { 0%, 45% { opacity: 1; } 50%, 95% { opacity: 0; } }
@media (max-width: 768px) {
  .dvkb__content:where([data-rk-5cdff8]) { padding-top: calc(var(--dvkb-reveal) * 0.75); }
}
@media (prefers-reduced-motion: reduce) { .dvkb__cursor:where([data-rk-5cdff8]) { animation: none; } }