Ir al contenido
Español
Operaciones booleanas viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Una figura de libro de texto sobre operaciones de conjuntos con áreas. Los contornos de un círculo A y de un triángulo o cuadrado B dividen el plano en tres regiones: solo en A, en ambos y solo en B. Una operación es una elección de esas regiones. La figura izquierda es la construcción: las regiones elegidas se tiñen y un barrido sobre ellas las añade o las quita; un punto en el centro de cada figura la mueve. La derecha muestra solo el resultado, relleno. La cabecera nombra la operación y su identidad de áreas; los botones dan el área de cada región y la lectura, la del resultado.

Úsalo para

  • Teach set operations with something you can measure: the union, intersection and differences of two shapes and the inclusion–exclusion identity for their areas.
  • Explain what union, subtract and intersect do in a vector drawing tool before learners use them.

Busca otra opción cuando

  • For editing real vector paths, use a drawing tool: the shapes here are fixed in size.

Uso

import React, { useState } from 'react'
import { CampBadgePress } from './CampBadgePress.jsx'

export function SetLesson() {
  const [operation, setOperation] = useState('intersection')
  const [area, setArea] = useState(null)
  return (
    <CampBadgePress
      value={operation}
      onChange={(next, details) => {
        setOperation(next)
        setArea(details.area)
      }}
      shape="square"
      labels={{ title: 'Where two shapes overlap' }}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
value'union' | 'intersection' | 'aMinusB' | 'bMinusA' | 'xor' | 'a' | 'b' | 'none'—Controlled result: the operation, or the set that the chosen regions make ('a', 'b' and 'none' are reached by sweeping or the region chips).
defaultValuestring'union'Starting result when uncontrolled, and what Reset returns to.
onChange(value, { reason, regions, area }) => void—Called with the new result and { reason ('operation', 'region', 'sweep', 'cancel' or 'reset'), regions ([A − B, A ∩ B, B − A] as 0 or 1), area (square units) }.
positions{ a: [x, y], b: [x, y] }—Controlled centres of the circle A and of shape B, in units on the 20 × 16 grid.
defaultPositions{ a: [x, y], b: [x, y] }{ a: [7.5, 8], b: [12.5, 8.6] }Starting centres when uncontrolled.
onPositionsChange(positions, { reason }) => void—Called while a shape is dragged or moved with the keys; reason is 'drag', 'key', 'cancel' or 'reset'.
shape'triangle' | 'square''triangle'Shape B: a triangle with base 10 and height 8, or a square with side 8. A is a circle of radius 5.
labelsobject—Replaces any built-in text: title, construction, result, operation, regions, names and formulas (objects keyed by result), regionNames (three), readout ('{set}'), empty, unit, moveA, moveB, help, regionText ('{name}', '{area}'), movedText ('{shape}', '{x}', '{y}', '{area}') and reset.
localestring'en'Language tag for the decimal readouts.
classNamestring—Extra class on the card, for example to set its width (30rem by default, never wider than its container).

Accesibilidad

  • The operations are a radio group labelled with their names (the visible text is the symbol): Tab reaches the chosen one, arrows move and select.
  • Each region is a toggle button (aria-pressed) whose name includes its area; sweeping on the figure does the same with a pointer.
  • Each shape's knob is a focusable button: arrows move the shape by 0.5 units, Shift with an arrow by 2. A polite status announces the new position and the overlap.
  • The area of the result is a polite live region; the result figure is an image labelled with the result's name and area. Reset is a button, marked unavailable while nothing has changed.
  • Dragging uses pointer capture; a cancelled gesture restores the regions or the position it started from. The construction figure sets touch-action none so a sweep does not scroll the page.

Movimiento

Region fills fade for --ds-duration-base; a shape moved with the keys glides for --ds-duration-fast and follows the pointer directly while dragged. With reduced motion every change lands at once.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

CampBadgePress.jsxcamp-badge-press.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Formularios
Cuadrícula de disponibilidad viene con Pro. La vista previa aparece al desbloquearlo.
Selector en cascada viene con Pro. La vista previa aparece al desbloquearlo.