Back to Mantine

7 14 0

apps/mantine.dev/src/pages/changelog/7-14-0.mdx

9.2.24.4 KB
Original Source

import { AngleSliderDemos, BarChartDemos, FunnelChartDemos, ModalDemos, RadialBarChartDemos, SliderDemos, } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';

export default Layout(MDX_DATA.Changelog7140);

AngleSlider component

New AngleSlider component:

<Demo data={AngleSliderDemos.marks} />

RadialBarChart component

New RadialBarChart component:

<Demo data={RadialBarChartDemos.labels} />

FunnelChart component

New FunnelChart component:

<Demo data={FunnelChartDemos.usage} />

New Modal.Stack and Drawer.Stack components simplify usage of multiple modals/drawers at the same time.

Use Modal.Stack component to render multiple modals at the same time. Modal.Stack keeps track of opened modals, manages z-index values, focus trapping and closeOnEscape behavior. Modal.Stack is designed to be used with useModalsStack hook.

Differences from using multiple Modal components:

  • Modal.Stack manages z-index values – modals that are opened later will always have higher z-index value disregarding their order in the DOM
  • Modal.Stack disables focus trap and Escape key handling for all modals except the one that is currently opened
  • Modals that are not currently opened are present in the DOM but are hidden with opacity: 0 and pointer-events: none
  • Only one overlay is rendered at a time
<Demo data={ModalDemos.stack} />

useModalsStack/useDrawersStack hooks

useModalsStack hook provides an easy way to control multiple modals at the same time. It accepts an array of unique modals ids and returns an object with the following properties:

tsx
interface ModalStackReturnType<T extends string> {
  // Current opened state of each modal
  state: Record<T, boolean>;

  // Opens modal with the given id
  open: (id: T) => void;

  // Closes modal with the given id
  close: (id: T) => void;

  // Toggles modal with the given id
  toggle: (id: T) => void;

  // Closes all modals within the stack
  closeAll: () => void;

  // Returns props for modal with the given id
  register: (id: T) => {
    opened: boolean;
    onClose: () => void;
    stackId: T;
  };
}

Example of using useModalsStack with Modal component:

tsx
import { Modal, useModalsStack } from '@mantine/core';

function Demo() {
  const stack = useModalsStack(['first', 'second']);

  return (
    <>
      <Modal {...stack.register('first')}>First</Modal>
      <Modal {...stack.register('second')}>Second</Modal>
      <Button onClick={() => stack.open('first')}>Open first</Button>
    </>
  );
}

Restrict Slider selection to marks

Slider component now supports restrictToMarks prop that restricts slider value to marks only. Note that in this case step prop is ignored:

<Demo data={SliderDemos.restrictToMarks} />

BarChart SVG pattern fill

BarChart now can be used with SVG pattern fill:

<Demo data={BarChartDemos.stripes} />

Help center updates

Other changes

  • useTree hook now accepts onNodeExpand and onNodeCollapse callbacks
  • useTree hook now returns additional checkAllNodes, uncheckAllNodes and setCheckedState handlers
  • Tree component now includes getTreeExpandedState to generate expanded state based on the tree data
  • use-form now supports form.replaceListItem handler to replace list item at given index