DocsGitHub
Getting Started
  • Overview
  • Design Tokens
Components
  • Accordion
  • Alert
  • Announcement
  • Avatar
  • Badge
  • BigCalendar
  • Breadcrumb
  • Button
  • ButtonGroup
  • Calendar
  • Card
  • Checkbox
  • Chip
  • CloseButton
  • Combobox
  • CommandPalette
  • ContextMenu
  • Currency
  • DatePicker
  • DescriptionList
  • Drawer
  • DropdownMenu
  • EmptyState
  • Field
  • FileUpload
  • FormGrid
  • Hotkey
  • Icon
  • Input
  • Metric
  • Modal
  • MultiSelect
  • NumberInput
  • Pagination
  • Popover
  • ProgressBar
  • Radio
  • Rating
  • SegmentedControl
  • Select
  • SelectionCard
  • Sidebar
  • Skeleton
  • Slider
  • Spinner
  • Stepper
  • Switch
  • Table
  • Tabs
  • Textarea
  • Timeline
  • TimePicker
  • Toast
  • Tooltip
  • TransferList
  • TreeView
  • Wizard
Charts
  • Overview
  • Area Chart
  • Bar Chart
  • Donut Chart
  • Line Chart
  • Pie Chart
  • Stacked Bar Chart

CloseButton

A small icon-only button for dismissing modals, toasts, chips, or any dismissible surface.

Default

The default CloseButton renders an X icon and is always accessible, even without an explicit aria-label.

tsx
<CloseButton />

Installation

tsx
import { CloseButton } from "madagent";

Sizes

tsx
<div style={{ display: "flex", gap: 12, alignItems: "center" }}>
  <CloseButton size="sm" />
  <CloseButton size="md" />
  <CloseButton size="lg" />
</div>

Custom Icon

Pass children to render a custom icon or label instead of the default X icon.

Custom icon

tsx
<CloseButton aria-label="Delete item">
  <Trash2 size={20} aria-hidden="true" />
</CloseButton>

Text content

Text children double as the accessible name, so no explicit aria-label is required.

tsx
<CloseButton>Dismiss</CloseButton>

Disabled

A disabled CloseButton cannot be clicked. It uses the semantic --md-content-disabled token for its icon color rather than opacity.

tsx
<div style={{ display: "flex", gap: 12, alignItems: "center" }}>
  <CloseButton disabled />
  <CloseButton size="lg" disabled />
</div>

In Context

A common placement: a flex row banner with the CloseButton at the inline-end, vertically centered against the content at any banner height. Flex row order and logical properties keep it on the correct side in both LTR and RTL.

Update available

A new version is ready to install.

tsx
<div
  style={{
    display: "flex",
    alignItems: "center",
    gap: "0.75rem",
    width: "18rem",
    padding: "0.75rem 1rem",
    borderRadius: "0.75rem",
    border: "1px solid var(--md-border-subtle)",
    backgroundColor: "var(--md-surface-parent)",
  }}
>
  <div style={{ flex: 1, minWidth: 0 }}>
    <h3 style={{ margin: 0, fontSize: "0.9375rem", fontWeight: 600 }}>
      Update available
    </h3>
    <p
      style={{
        marginBlockStart: "0.25rem",
        marginBlockEnd: 0,
        fontSize: "0.875rem",
        color: "var(--md-content-secondary)",
      }}
    >
      A new version is ready to install.
    </p>
  </div>
  <CloseButton size="sm" />
</div>

API Reference

PropTypeDefaultDescription
size
"sm""md""lg"
"md"Controls the button and icon dimensions
children
ReactNode
-Custom icon or content. Defaults to an X icon
disabled
boolean
falseDisables the button using the native disabled attribute
type
"button""submit""reset"
"button"Native button type attribute
aria-label
string
-Accessible name. Defaults to "Close" when no accessible text is otherwise provided (e.g. the default or a custom icon); an explicit aria-label always wins
onClick
(e: MouseEvent<HTMLButtonElement>) => void
-Called when the button is clicked

RTL Support

Components automatically adapt to right-to-left languages using CSS logical properties.

Preview

تحديث متوفر

Usage

tsx
<div
  style={{
    display: "flex",
    alignItems: "center",
    gap: "0.75rem",
    width: "16rem",
    padding: "0.75rem 1rem",
    borderRadius: "0.75rem",
    border: "1px solid var(--md-border-subtle)",
    backgroundColor: "var(--md-surface-parent)",
  }}
>
  <h3 style={{ margin: 0, flex: 1, minWidth: 0, fontSize: "0.9375rem", fontWeight: 600 }}>
    تحديث متوفر
  </h3>
  <CloseButton size="sm" aria-label="إغلاق" />
</div>