material-plus-ui 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/animate-appear/MPAnimateAppear.d.ts +56 -0
- package/dist/components/animate-appear/MPAnimateAppear.js +1 -0
- package/dist/components/animate-appear/index.d.ts +2 -0
- package/dist/components/animate-appear/index.js +1 -0
- package/dist/components/animate-blink/MPAnimateBlink.d.ts +41 -0
- package/dist/components/animate-blink/MPAnimateBlink.js +1 -0
- package/dist/components/animate-blink/index.d.ts +2 -0
- package/dist/components/animate-blink/index.js +1 -0
- package/dist/components/animate-fade/MPAnimateFade.d.ts +38 -0
- package/dist/components/animate-fade/MPAnimateFade.js +1 -0
- package/dist/components/animate-fade/index.d.ts +2 -0
- package/dist/components/animate-fade/index.js +1 -0
- package/dist/components/animate-grow/MPAnimateGrow.d.ts +52 -0
- package/dist/components/animate-grow/MPAnimateGrow.js +1 -0
- package/dist/components/animate-grow/index.d.ts +2 -0
- package/dist/components/animate-grow/index.js +1 -0
- package/dist/components/animate-headline/MPAnimateHeadline.d.ts +63 -0
- package/dist/components/animate-headline/MPAnimateHeadline.js +1 -0
- package/dist/components/animate-headline/index.d.ts +2 -0
- package/dist/components/animate-headline/index.js +1 -0
- package/dist/components/animate-lighting/MPAnimateLighting.d.ts +68 -0
- package/dist/components/animate-lighting/MPAnimateLighting.js +1 -0
- package/dist/components/animate-lighting/index.d.ts +2 -0
- package/dist/components/animate-lighting/index.js +1 -0
- package/dist/components/animate-marquee/MPAnimateMarquee.d.ts +66 -0
- package/dist/components/animate-marquee/MPAnimateMarquee.js +1 -0
- package/dist/components/animate-marquee/index.d.ts +2 -0
- package/dist/components/animate-marquee/index.js +1 -0
- package/dist/components/animate-rotate/MPAnimateRotate.d.ts +56 -0
- package/dist/components/animate-rotate/MPAnimateRotate.js +1 -0
- package/dist/components/animate-rotate/index.d.ts +2 -0
- package/dist/components/animate-rotate/index.js +1 -0
- package/dist/components/animate-slide/MPAnimateSlide.d.ts +53 -0
- package/dist/components/animate-slide/MPAnimateSlide.js +1 -0
- package/dist/components/animate-slide/index.d.ts +2 -0
- package/dist/components/animate-slide/index.js +1 -0
- package/dist/components/animate-typing/MPAnimateTyping.d.ts +59 -0
- package/dist/components/animate-typing/MPAnimateTyping.js +1 -0
- package/dist/components/animate-typing/index.d.ts +2 -0
- package/dist/components/animate-typing/index.js +1 -0
- package/dist/components/animate-zoom/MPAnimateZoom.d.ts +44 -0
- package/dist/components/animate-zoom/MPAnimateZoom.js +1 -0
- package/dist/components/animate-zoom/index.d.ts +2 -0
- package/dist/components/animate-zoom/index.js +1 -0
- package/dist/components/avatar/MPAvatar.d.ts +9 -2
- package/dist/components/avatar/MPAvatar.js +1 -1
- package/dist/components/badge/MPBadge.js +1 -1
- package/dist/components/bottom-navigation/MPBottomNavigation.d.ts +144 -0
- package/dist/components/bottom-navigation/MPBottomNavigation.js +1 -0
- package/dist/components/bottom-navigation/index.d.ts +2 -0
- package/dist/components/bottom-navigation/index.js +1 -0
- package/dist/components/breadcrumb/MPBreadcrumb.d.ts +22 -0
- package/dist/components/breadcrumb/MPBreadcrumb.js +1 -1
- package/dist/components/button/MPButton.d.ts +7 -2
- package/dist/components/button/MPButton.js +1 -1
- package/dist/components/carousel/MPCarousel.js +1 -1
- package/dist/components/checkbox/MPCheckbox.d.ts +2 -2
- package/dist/components/checkbox/MPCheckbox.js +1 -1
- package/dist/components/chip/MPChip.d.ts +13 -3
- package/dist/components/chip/MPChip.js +1 -1
- package/dist/components/color-picker/MPColorPicker.d.ts +21 -3
- package/dist/components/color-picker/MPColorPicker.js +1 -1
- package/dist/components/combobox/MPCombobox.d.ts +38 -10
- package/dist/components/combobox/MPCombobox.js +1 -1
- package/dist/components/container/MPContainer.d.ts +75 -0
- package/dist/components/container/MPContainer.js +1 -0
- package/dist/components/container/index.d.ts +2 -0
- package/dist/components/container/index.js +1 -0
- package/dist/components/date-picker/MPDatePicker.d.ts +3 -0
- package/dist/components/date-picker/MPDatePicker.js +1 -1
- package/dist/components/date-range-picker/MPDateRangePicker.js +1 -1
- package/dist/components/date-time-picker/MPDateTimePicker.js +1 -1
- package/dist/components/dialog/MPDialog.d.ts +8 -3
- package/dist/components/dialog/MPDialog.js +1 -1
- package/dist/components/drawer/MPDrawer.d.ts +33 -9
- package/dist/components/drawer/MPDrawer.js +1 -1
- package/dist/components/empty/MPEmpty.d.ts +12 -2
- package/dist/components/empty/MPEmpty.js +1 -1
- package/dist/components/file-picker/MPFilePicker.d.ts +11 -1
- package/dist/components/file-picker/MPFilePicker.js +1 -1
- package/dist/components/floating-action-button/MPFloatingActionButton.d.ts +126 -0
- package/dist/components/floating-action-button/MPFloatingActionButton.js +1 -0
- package/dist/components/floating-action-button/index.d.ts +2 -0
- package/dist/components/floating-action-button/index.js +1 -0
- package/dist/components/grid/MPGrid.d.ts +155 -0
- package/dist/components/grid/MPGrid.js +1 -0
- package/dist/components/grid/index.d.ts +2 -0
- package/dist/components/grid/index.js +1 -0
- package/dist/components/highlight/MPHighlight.js +1 -1
- package/dist/components/list/MPList.js +1 -1
- package/dist/components/menu/MPMenu.d.ts +10 -1
- package/dist/components/menu/MPMenu.js +1 -1
- package/dist/components/number-field/MPNumberField.d.ts +21 -3
- package/dist/components/number-field/MPNumberField.js +1 -1
- package/dist/components/pagination/MPPagination.d.ts +106 -0
- package/dist/components/pagination/MPPagination.js +1 -0
- package/dist/components/pagination/index.d.ts +2 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/panes/MPPanes.js +1 -1
- package/dist/components/pill/MPPill.js +1 -1
- package/dist/components/popover/MPPopover.d.ts +8 -3
- package/dist/components/popover/MPPopover.js +1 -1
- package/dist/components/radio-group/MPRadioGroup.js +1 -1
- package/dist/components/rating/MPRating.d.ts +135 -0
- package/dist/components/rating/MPRating.js +1 -0
- package/dist/components/rating/index.d.ts +2 -0
- package/dist/components/rating/index.js +1 -0
- package/dist/components/segmented-button/MPSegmentedButton.js +1 -1
- package/dist/components/select/MPSelect.d.ts +23 -6
- package/dist/components/select/MPSelect.js +1 -1
- package/dist/components/skeleton/MPSkeleton.js +1 -1
- package/dist/components/slider/MPSlider.js +1 -1
- package/dist/components/snackbar/MPSnackbar.d.ts +8 -3
- package/dist/components/snackbar/MPSnackbar.js +1 -1
- package/dist/components/spoiler/MPSpoiler.js +1 -1
- package/dist/components/switch/MPSwitch.d.ts +2 -2
- package/dist/components/switch/MPSwitch.js +1 -1
- package/dist/components/table/MPTable.d.ts +14 -1
- package/dist/components/table/MPTable.js +1 -1
- package/dist/components/tabs/MPTabs.d.ts +145 -0
- package/dist/components/tabs/MPTabs.js +1 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/text-field/MPTextField.d.ts +37 -7
- package/dist/components/text-field/MPTextField.js +1 -1
- package/dist/components/text-link/MPTextLink.js +1 -1
- package/dist/components/time-picker/MPTimePicker.js +1 -1
- package/dist/components/timeline/MPTimeline.js +1 -1
- package/dist/constants/icons.d.ts +13 -0
- package/dist/constants/icons.js +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1 -1
- package/dist/internal/Calendar.js +1 -1
- package/dist/internal/FieldOutline.d.ts +75 -4
- package/dist/internal/FieldOutline.js +1 -1
- package/dist/internal/Picker.d.ts +52 -9
- package/dist/internal/Picker.js +1 -1
- package/dist/internal/animate.d.ts +179 -0
- package/dist/internal/animate.js +1 -0
- package/dist/internal/date.d.ts +2 -2
- package/dist/internal/date.js +1 -1
- package/dist/internal/i18n.d.ts +110 -0
- package/dist/internal/i18n.js +1 -1
- package/dist/internal/inert.d.ts +11 -0
- package/dist/internal/inert.js +1 -0
- package/dist/internal/surface.d.ts +42 -12
- package/dist/internal/surface.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +640 -4
- package/dist/types.d.ts +155 -0
- package/package.json +10 -10
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type MPMessages } from '../../internal/i18n';
|
|
3
|
+
import type { MPColor, MPStyleProps } from '../../types';
|
|
4
|
+
/** The words the row says on its own behalf. */
|
|
5
|
+
export type MPPaginationLabels = MPMessages['pagination'];
|
|
6
|
+
export interface MPPaginationProps extends MPStyleProps, Omit<React.ComponentPropsWithoutRef<'nav'>, 'color' | 'onChange'> {
|
|
7
|
+
/**
|
|
8
|
+
* How many pages there are. Fewer than two and the whole control renders
|
|
9
|
+
* nothing — one page is not a set of pages, and a row holding a lone disabled
|
|
10
|
+
* "1" is a control advertising that it has nothing to do.
|
|
11
|
+
*/
|
|
12
|
+
count: number;
|
|
13
|
+
/** The current page, 1-based. Use with `onPageChange` for a controlled row. */
|
|
14
|
+
page?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Which page starts current, for an uncontrolled row.
|
|
17
|
+
* @default 1
|
|
18
|
+
*/
|
|
19
|
+
defaultPage?: number;
|
|
20
|
+
/** Called with the page that was chosen. */
|
|
21
|
+
onPageChange?: (page: number) => void;
|
|
22
|
+
/**
|
|
23
|
+
* How many pages are always shown on either side of the current one.
|
|
24
|
+
* @default 1
|
|
25
|
+
*/
|
|
26
|
+
siblingCount?: number;
|
|
27
|
+
/**
|
|
28
|
+
* How many pages are always shown at each end, whatever page is current. `0`
|
|
29
|
+
* drops the first and last page from the row, leaving only the window.
|
|
30
|
+
* @default 1
|
|
31
|
+
*/
|
|
32
|
+
boundaryCount?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Shows the two steppers that jump to the first and last page.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
showEdges?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Shows the two steppers that move by one page.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
showArrows?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Which accent family the current page is filled with.
|
|
45
|
+
* @default 'primary'
|
|
46
|
+
*/
|
|
47
|
+
color?: MPColor;
|
|
48
|
+
/** Unavailable. Every cell in the row stops answering. */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The address of a page, which turns every number in the row into a real link.
|
|
52
|
+
*
|
|
53
|
+
* Without it the row is buttons, and a crawler cannot press one — so a paged
|
|
54
|
+
* list of articles, products or search results exists for a reader and stops
|
|
55
|
+
* at page one for everything else. With it the numbers are `<a href>`, the two
|
|
56
|
+
* steppers carry `rel="prev"` and `rel="next"`, and the browser's own
|
|
57
|
+
* behaviour comes back: open in a new tab, copy the address, see where a press
|
|
58
|
+
* is going before making it.
|
|
59
|
+
*
|
|
60
|
+
* `onPageChange` still fires and the navigation is still cancelled first, so a
|
|
61
|
+
* client-side router keeps the page it already has.
|
|
62
|
+
*/
|
|
63
|
+
getPageHref?: (page: number) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Which language the row names itself in — a BCP 47 tag such as `ko`, `pt-BR`
|
|
66
|
+
* or `zh-Hant`. Unsupported tags fall back to English.
|
|
67
|
+
*
|
|
68
|
+
* Nothing here is ever drawn, so without it a Korean page reads its pages out
|
|
69
|
+
* in English.
|
|
70
|
+
*/
|
|
71
|
+
locale?: string;
|
|
72
|
+
/** Overrides for the words themselves. They win over the translation. */
|
|
73
|
+
labels?: Partial<MPPaginationLabels>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A row of pages, one of which is the one being read.
|
|
77
|
+
*
|
|
78
|
+
* Material has no pagination component, so what is Material here is everything
|
|
79
|
+
* *around* the decision: the cells are pills at the library's own control
|
|
80
|
+
* heights, the current one is filled with the accent under its own ink, the rest
|
|
81
|
+
* are the quiet `text` treatment, and every one of them carries the state layer
|
|
82
|
+
* the specification uses in place of a hover colour.
|
|
83
|
+
*
|
|
84
|
+
* The current page is the one thing the row has to say without being read, which
|
|
85
|
+
* is why it is the only cell that is filled. Nine filled cells in a row would say
|
|
86
|
+
* that all nine are the primary action.
|
|
87
|
+
*
|
|
88
|
+
* ## The markup, and why it is that
|
|
89
|
+
*
|
|
90
|
+
* A `<nav>` around a `<ul>`: a named landmark a screen reader can skip, holding
|
|
91
|
+
* a list whose length says how far the pages go, with `aria-current="page"`
|
|
92
|
+
* marking where the reader is. The ellipsis is a `<span>` rather than a disabled
|
|
93
|
+
* button — it is not a control that happens to be unavailable, it is
|
|
94
|
+
* punctuation — and it is `aria-hidden`, because "horizontal ellipsis" read out
|
|
95
|
+
* between two numbers is noise.
|
|
96
|
+
*
|
|
97
|
+
* ## Why it builds its own cells
|
|
98
|
+
*
|
|
99
|
+
* For the reason [MPSegmentedButton](../inputs/segmented-button) does: a page
|
|
100
|
+
* cell is square-ish and grows only for a long number, which is not a shape
|
|
101
|
+
* [MPButton](../inputs/button) has — a button is a pill with inline padding
|
|
102
|
+
* proportional to its height, and nine of those in a row is a very long row. The
|
|
103
|
+
* heights, the type scale and the state layer are the shared ones, so a `sm`
|
|
104
|
+
* pagination still lines up with a `sm` button beside it.
|
|
105
|
+
*/
|
|
106
|
+
export declare const MPPagination: React.ForwardRefExoticComponent<MPPaginationProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as t from"react";import{MPIcon as a}from"../icon/MPIcon";import{ChevronLeftIcon as i,ChevronRightIcon as r,ChevronsLeftIcon as l,ChevronsRightIcon as o}from"../../constants/icons";import{accentSlots as s}from"../../internal/accent";import{fillMessage as m}from"../../internal/i18n";import{useMPLocale as c,useMPMessages as p}from"../../internal/locale";import{MPStateLayer as u}from"../../internal/StateLayer";import{CONTROL_ICON as f,CONTROL_TEXT as d}from"../../internal/scale";import{VISUALLY_HIDDEN as h}from"../../internal/visually-hidden";const g={xs:"h-8 min-w-8 px-1.5",sm:"h-10 min-w-10 px-2",md:"h-14 min-w-14 px-2.5",lg:"h-16 min-w-16 px-3",xl:"h-18 min-w-18 px-3.5"},x={xs:"gap-0.5",sm:"gap-1",md:"gap-1",lg:"gap-1.5",xl:"gap-2"};function b(e,n){return Array.from({length:Math.max(0,n-e+1)},(n,t)=>e+t)}export const MPPagination=t.forwardRef(function({count:y,page:v,defaultPage:M=1,onPageChange:w,siblingCount:N=1,boundaryCount:j=1,showEdges:P=!1,showArrows:C=!0,size:S="md",color:K="primary",fullWidth:_=!1,disabled:k=!1,getPageHref:z,locale:$,labels:A,className:B,style:D,...E},H){const I=c($),L=p("pagination",I,A),[R,W]=t.useState(M),q=void 0!==v,F=Math.min(Math.max(v??R,1),Math.max(y,1));if(y<2)return null;const G=function(e,n,t,a){const i=b(1,Math.min(a,e)),r=b(Math.max(e-a+1,a+1),e),l=Math.max(Math.min(n-t,e-a-2*t-1),a+2),o=Math.min(Math.max(n+t,a+2*t+2),r.length>0?r[0]-2:e-1);return[...i,...l>a+2?["start-ellipsis"]:a+1<e-a?[a+1]:[],...b(l,o),...o<e-a-1?["end-ellipsis"]:e-a>a?[e-a]:[],...r]}(y,F,N,j),J=F<=1,O=F>=y,Q=(e,n)=>{e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||z&&!w||(e.preventDefault(),(e=>{const n=Math.min(Math.max(e,1),y);n!==F&&(q||W(n),w?.(n))})(n))},T=(e,n)=>["mp-pagination__cell group relative inline-flex items-center justify-center","rounded-mp-full box-border appearance-none overflow-hidden align-middle select-none","border-0 font-[inherit] tabular-nums whitespace-nowrap no-underline","transition-[background-color,color] duration-(--mp-sys-motion-duration-short4)","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-2","focus-visible:outline-solid outline-none",g[S],d[S],n?"text-mp-on-surface/38 cursor-default bg-transparent":e?"bg-(--_mp-accent) text-(--_mp-on-accent) cursor-pointer":"text-mp-on-surface cursor-pointer bg-transparent"].join(" "),U=(t,a,i,r,l,o,s)=>e("li",{className:"flex",children:!z||i||r?n("button",{type:"button",disabled:i,"aria-label":l,"aria-current":r?"page":void 0,className:T(r,i),onClick:e=>Q(e,a),children:[i?null:e(u,{}),e("span",{className:"relative",children:o})]}):n("a",{href:z(a),rel:s,"aria-label":l,className:T(!1,!1),onClick:e=>Q(e,a),children:[e(u,{}),e("span",{className:"relative",children:o})]})},t),V=n=>e(a,{icon:n,size:f[S],className:"rtl:rotate-180"});return n("nav",{ref:H,"aria-label":L.label,"data-mp-size":S,className:["mp-pagination flex",_?"w-full justify-center":"",B??""].filter(Boolean).join(" "),style:{...s(K),...D},...E,children:[n("ul",{role:"list",className:`m-0 flex list-none items-center p-0 ${x[S]}`,children:[P?U("first",1,k||J,!1,L.first,V(l)):null,C?U("previous",F-1,k||J,!1,L.previous,V(i),"prev"):null,G.map((n,t)=>"number"==typeof n?U(`slot-${t}`,n,k,n===F,m(L.page,{page:String(n)}),n):e("li",{"aria-hidden":"true",className:["text-mp-on-surface-variant flex items-center justify-center select-none",g[S],d[S]].join(" "),children:"…"},`slot-${t}`)),C?U("next",F+1,k||O,!1,L.next,V(r),"next"):null,P?U("last",y,k||O,!1,L.last,V(o)):null]}),e("span",{className:h,"aria-live":"polite",children:m(L.status,{page:String(F),total:String(y)})})]})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{MPPagination}from"./MPPagination";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as n from"react";import{accentSlots as r}from"../../internal/accent";const o=n.createContext({basis:null}),i={xs:"basis-1",sm:"basis-1.5",md:"basis-2",lg:"basis-2.5",xl:"basis-3"},a={xs:4,sm:6,md:8,lg:10,xl:12};function s(e,t,n){if(null==e)return;if("number"==typeof e)return t*e/100;const r=/^\s*(-?[\d.]+)\s*(px|rem|em|%)\s*$/.exec(e);if(!r)return;const o=Number(r[1]);if(!Number.isNaN(o))switch(r[2]){case"px":return o;case"%":return t*o/100;case"rem":return o*Number.parseFloat(getComputedStyle(document.documentElement).fontSize||"16");case"em":return o*Number.parseFloat(n&&getComputedStyle(n).fontSize||"16");default:return}}export const MPPanes=n.forwardRef(function({orientation:l="horizontal",resizable:
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as n from"react";import{accentSlots as r}from"../../internal/accent";const o=n.createContext({basis:null,id:null}),i={xs:"basis-1",sm:"basis-1.5",md:"basis-2",lg:"basis-2.5",xl:"basis-3"},a={xs:4,sm:6,md:8,lg:10,xl:12};function s(e,t,n){if(null==e)return;if("number"==typeof e)return t*e/100;const r=/^\s*(-?[\d.]+)\s*(px|rem|em|%)\s*$/.exec(e);if(!r)return;const o=Number(r[1]);if(!Number.isNaN(o))switch(r[2]){case"px":return o;case"%":return t*o/100;case"rem":return o*Number.parseFloat(getComputedStyle(document.documentElement).fontSize||"16");case"em":return o*Number.parseFloat(n&&getComputedStyle(n).fontSize||"16");default:return}}export const MPPanes=n.forwardRef(function({orientation:l="horizontal",resizable:u=!0,color:c="primary",size:m="md",onResize:d,onResizeEnd:f,className:p,style:h,children:g,...v},b){const x=n.Children.toArray(g).filter(n.isValidElement),y=x.length,z=n.useId(),w=n.useRef(null),S=n.useCallback(e=>{w.current=e,"function"==typeof b?b(e):b&&(b.current=e)},[b]),E=n.useRef([]),N=x.map(e=>e.props),[R,M]=n.useState(null),j=R&&R.length===y?R:null,C=n.useRef(null);n.useLayoutEffect(()=>{E.current=N,C.current=j});const k=n.useRef(null);n.useEffect(()=>()=>{null!==k.current&&(document.body.style.userSelect=k.current,k.current=null)},[]);const L="horizontal"===l,$=a[m]*Math.max(0,y-1);function P(e){const t=w.current,n=C.current;if(!u||!t||!n||void 0===n[e+1])return null;const r=t.getBoundingClientRect(),o=(L?r.width:r.height)-$;if(o<=0)return null;const i=E.current[e],a=E.current[e+1],l=n[e]*o,c=l+n[e+1]*o,m=Math.max(s(i?.minSize,o,t)??0,c-(s(a?.maxSize,o,t)??c)),f=Math.min(s(i?.maxSize,o,t)??c,c-(s(a?.minSize,o,t)??0));return f<m?null:{root:t,current:n,lower:m,upper:f,start:l,resize(t){const r=Math.min(f,Math.max(m,l+t)),i=[...n];return i[e]=r/o,i[e+1]=(c-r)/o,M(i),d?.(i.map(e=>100*e)),i}}}n.useEffect(()=>{const e=w.current;if(!e)return;const t=()=>{const t=e.getBoundingClientRect(),n=(L?t.width:t.height)-$;n<=0||M(t=>t&&t.length===y?t:function(e,t,n){const r=e.map(e=>s(e.defaultSize,t,n)),o=r.reduce((e,t)=>e+(t??0),0),i=r.filter(e=>void 0===e).length,a=i>0?Math.max(0,t-o)/i:0,l=r.map(e=>Math.max(0,e??a)),u=l.reduce((e,t)=>e+t,0);return u<=0?l.map(()=>1/Math.max(1,l.length)):l.map(e=>e/u)}(E.current,n,e))};t();const n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[y,L,$]);const _=["mp-panes__handle group/handle relative z-1 flex shrink-0 grow-0 items-center justify-center",i[m],"transition-colors duration-(--mp-sys-motion-duration-short4)","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-0","focus-visible:outline-solid outline-none",u?[L?"cursor-col-resize":"cursor-row-resize","hover:bg-(--_mp-accent)/8 data-[dragging]:bg-(--_mp-accent)/10"].join(" "):""].filter(Boolean).join(" ");return e("div",{ref:S,"data-mp-size":m,className:["mp-panes flex h-full w-full",L?"flex-row":"flex-col","min-h-0 min-w-0",p??""].filter(Boolean).join(" "),style:{...r(c),...h},...v,children:x.map((r,i)=>t(n.Fragment,{children:[i>0?e("div",{role:"separator","aria-orientation":L?"vertical":"horizontal","aria-valuenow":j?Math.round(100*j[i-1]):void 0,"aria-valuemin":0,"aria-valuemax":100,"aria-disabled":!u||void 0,"aria-controls":`${z}-${i-1}`,tabIndex:u?0:-1,className:_,onPointerDown:e=>{0===e.button&&function(e,t){const n=P(e);if(!n)return;const r=t.currentTarget;try{r.setPointerCapture(t.pointerId)}catch{}r.dataset.dragging="true";const o=document.body.style.userSelect;k.current=o,document.body.style.userSelect="none";const i=L?t.clientX:t.clientY,a=L&&"rtl"===getComputedStyle(n.root).direction?-1:1;let s=n.current;const l=e=>{const t=L?e.clientX:e.clientY;s=n.resize((t-i)*a)},u=()=>{r.removeEventListener("pointermove",l),r.removeEventListener("pointerup",u),r.removeEventListener("pointercancel",u),delete r.dataset.dragging,document.body.style.userSelect=o,k.current=null,f?.(s.map(e=>100*e))};r.addEventListener("pointermove",l),r.addEventListener("pointerup",u),r.addEventListener("pointercancel",u)}(i-1,e)},onKeyDown:e=>{const t=L?"ArrowLeft":"ArrowUp",n=L?"ArrowRight":"ArrowDown";if(e.key===t||e.key===n)return e.preventDefault(),void function(e,t){const n=P(e);if(!n)return;const r=n.resize(t);f?.(r.map(e=>100*e))}(i-1,e.key===n?16:-16);"Home"!==e.key&&"End"!==e.key||(e.preventDefault(),function(e,t){const n=P(e);if(!n)return;const r=n.resize(n[t]-n.start);f?.(r.map(e=>100*e))}(i-1,"Home"===e.key?"lower":"upper"))},children:e("span",{"aria-hidden":"true",className:["bg-mp-outline-variant pointer-events-none","transition-colors duration-(--mp-sys-motion-duration-short4)",L?"h-full w-px":"h-px w-full",u?["group-hover/handle:bg-(--_mp-accent)","group-focus-visible/handle:bg-(--_mp-accent)","group-data-[dragging]/handle:bg-(--_mp-accent)"].join(" "):""].filter(Boolean).join(" ")})}):null,e(o.Provider,{value:{basis:j?`calc((100% - ${$}px) * ${j[i].toFixed(6)})`:null,id:`${z}-${i}`},children:r})]},r.key??i))})});export const MPPane=n.forwardRef(function({defaultSize:t,minSize:r,maxSize:i,className:a,style:s,children:l,...u},c){const{basis:m,id:d}=n.useContext(o);return e("div",{ref:c,id:d??void 0,className:["mp-pane relative min-h-0 min-w-0 overflow-auto",a??""].filter(Boolean).join(" "),style:{flex:m?`0 0 ${m}`:"1 1 0%",...s},...u,children:l})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as o from"react";import{accentSlots as i}from"../../internal/accent";import{
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as o from"react";import{accentSlots as i}from"../../internal/accent";import{inertProps as r}from"../../internal/inert";import{MPStateLayer as s}from"../../internal/StateLayer";import{CONTROL_GAP as a,CONTROL_ICON as l,CONTROL_TEXT as c,hasContent as m,META_TEXT as d,PROSE_TEXT as p,SHEET_PAD_X as u}from"../../internal/scale";const f={xs:"min-h-8",sm:"min-h-10",md:"min-h-14",lg:"min-h-16",xl:"min-h-18"},h={xs:"px-4",sm:"px-5",md:"px-6",lg:"px-8",xl:"px-10"},x={filled:"shadow-mp-2 bg-(--_mp-accent) text-(--_mp-on-accent)",tonal:"shadow-mp-2 bg-(--_mp-accent-container) text-(--_mp-on-accent-container)",elevated:"shadow-mp-2 bg-mp-surface-container-low text-(--_mp-accent)",outlined:"border-mp-outline shadow-mp-1 border bg-mp-surface-container text-mp-on-surface",text:"shadow-mp-1 bg-mp-surface-container text-mp-on-surface"},b={static:{top:"",bottom:""},sticky:{top:"sticky top-3 z-20",bottom:"sticky bottom-3 z-20"},fixed:{top:"fixed inset-x-0 top-3 z-30 mx-auto w-fit",bottom:"fixed inset-x-0 bottom-3 z-30 mx-auto w-fit"}};export const MPPill=o.forwardRef(function({startIcon:w,endIcon:v,title:g,description:y,details:j,expanded:N=!1,position:k="static",side:_="top",onClick:z,variant:B="filled",size:C="md",color:I="secondary",className:R,style:$,children:H,...P},S){const E=o.useRef(null),F=o.useId(),[L,M]=o.useState(0);o.useEffect(()=>{const e=E.current;if(!e)return;const t=new ResizeObserver(()=>M(e.scrollHeight));return t.observe(e),M(e.scrollHeight),()=>t.disconnect()},[j]);const O=Boolean(z),q=u[C],A=t(n,{children:[m(w)?e("span",{className:"flex shrink-0 items-center justify-center overflow-hidden rounded-mp-full [&_img]:size-full [&_img]:object-cover",style:{width:l[C],height:l[C]},children:w}):null,m(g)||m(y)||m(H)?t("span",{className:["flex min-w-0 flex-1 flex-col items-center justify-center text-center",h[C]].join(" "),children:[m(g)?e("span",{className:"max-w-full truncate",children:g}):null,m(y)?e("span",{className:`max-w-full truncate font-normal ${d} [color:color-mix(in_oklab,currentColor_72%,transparent)]`,children:y}):null,H]}):null]});return t("div",{ref:S,"data-mp-size":C,"data-mp-variant":B,"data-mp-expanded":N||void 0,className:["mp-pill inline-flex max-w-full flex-col overflow-hidden align-middle","box-border whitespace-nowrap select-none",N?"rounded-mp-xl":"rounded-mp-full","transition-[border-radius,background-color,box-shadow]","duration-(--mp-sys-motion-duration-short4) ease-mp-standard","motion-reduce:transition-none",c[C],x[B],b[k][_],R??""].filter(Boolean).join(" "),style:{...i(I),...$},...P,children:[t("div",{className:["flex shrink-0 items-center py-1",f[C],a[C],O?"ps-0":q,m(v)?"pe-1":O?"pe-0":""].filter(Boolean).join(" "),children:[O?t("button",{type:"button",className:["group relative flex min-w-0 flex-1 cursor-pointer items-center justify-center","self-stretch appearance-none border-0 bg-transparent font-[inherit] text-inherit","rounded-[inherit]",a[C],q,"outline-mp-secondary focus-visible:outline-2 focus-visible:-outline-offset-2","focus-visible:outline-solid outline-none"].join(" "),"aria-expanded":m(j)?N:void 0,"aria-controls":m(j)?F:void 0,onClick:z,children:[e(s,{}),A]}):A,m(v)?e("span",{className:"flex h-[1lh] shrink-0 items-center",children:v}):null]}),m(j)?e("div",{id:F,className:["overflow-hidden","transition-[height] duration-(--mp-sys-motion-duration-short4) ease-mp-standard","motion-reduce:transition-none"].join(" "),style:{height:N?L:0},...r(!N),children:e("div",{ref:E,className:`${q} pb-2 whitespace-normal ${p[C]}`,children:j})}):null]})});
|
|
@@ -81,10 +81,15 @@ export interface MPPopoverProps {
|
|
|
81
81
|
*/
|
|
82
82
|
showClose?: boolean;
|
|
83
83
|
/**
|
|
84
|
-
* Accessible name of the × button.
|
|
85
|
-
*
|
|
84
|
+
* Accessible name of the × button. Defaults to the word for "close" in
|
|
85
|
+
* `locale`.
|
|
86
86
|
*/
|
|
87
87
|
closeLabel?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Which language the × button's default name is written in. Falls back to the
|
|
90
|
+
* nearest `MPLocaleProvider`, then to English.
|
|
91
|
+
*/
|
|
92
|
+
locale?: string;
|
|
88
93
|
/**
|
|
89
94
|
* A hard cap on the popup's width, overriding the one `size` implies. Numbers
|
|
90
95
|
* are pixels. For the popover whose *content* decides its width — a form, a
|
|
@@ -135,4 +140,4 @@ export declare const MPPopoverClose: React.ForwardRefExoticComponent<Omit<import
|
|
|
135
140
|
* dialog's `surface-container-high` at elevation 3, because a popover has not
|
|
136
141
|
* taken the page and should not sit above the menus that did not either.
|
|
137
142
|
*/
|
|
138
|
-
export declare function MPPopover({ trigger, title, description, side, align, sideOffset, alignOffset, arrow, open, defaultOpen, onOpenChange, modal, dismissible, showClose, closeLabel, width, size, className, style, children }: MPPopoverProps): React.JSX.Element;
|
|
143
|
+
export declare function MPPopover({ trigger, title, description, side, align, sideOffset, alignOffset, arrow, open, defaultOpen, onOpenChange, modal, dismissible, showClose, closeLabel, locale: localeProp, width, size, className, style, children }: MPPopoverProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{Popover as t}from"@base-ui/react/popover";import{MPIcon as i}from"../icon/MPIcon";import{CloseIcon as a}from"../../constants/icons";import{MPStateLayer as s}from"../../internal/StateLayer";import{hasContent as
|
|
1
|
+
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{Popover as t}from"@base-ui/react/popover";import{MPIcon as i}from"../icon/MPIcon";import{CloseIcon as a}from"../../constants/icons";import{useMPLocale as l,useMPMessages as r}from"../../internal/locale";import{MPStateLayer as s}from"../../internal/StateLayer";import{hasContent as n,META_TEXT as c,PROSE_TEXT as m,SHEET_GAP as d,SHEET_PAD as p,SHEET_TITLE as f}from"../../internal/scale";import{FADE as u,PORTAL_LAYER as x}from"../../internal/surface";const h={xs:"max-w-56",sm:"max-w-64",md:"max-w-80",lg:"max-w-96",xl:"max-w-lg"},g={xs:8,sm:9,md:10,lg:11,xl:12};export const MPPopoverClose=t.Close;export function MPPopover({trigger:v,title:b,description:w,side:N="bottom",align:O="center",sideOffset:P=8,alignOffset:j=0,arrow:y=!1,open:C,defaultOpen:z,onOpenChange:k,modal:M=!1,dismissible:L=!0,showClose:$=!1,closeLabel:B,locale:T,width:A,size:D="md",className:I,style:R,children:S}){const W=l(T),_=r("common",W),q=n(b)||n(w),E=g[D];return o(t.Root,{open:C,defaultOpen:z,modal:M,onOpenChange:(e,o)=>{L||e||"escape-key"!==o.reason&&"outside-press"!==o.reason&&"focus-out"!==o.reason?k?.(e):o.cancel()},children:[v?e(t.Trigger,{render:v}):null,e(t.Portal,{children:e(t.Positioner,{className:x,side:N,align:O,sideOffset:P,alignOffset:j,children:o(t.Popup,{"data-mp-size":D,className:["mp-popover rounded-mp-md relative flex flex-col outline-none","bg-mp-surface-container text-mp-on-surface shadow-mp-2","box-border",p[D],d[D],m[D],void 0===A?h[D]:"",u,I??""].filter(Boolean).join(" "),style:{...void 0===A?null:{maxWidth:"number"==typeof A?`${A}px`:A},...R},children:[y?e(t.Arrow,{className:["data-[side=top]:bottom-[-1px]","data-[side=bottom]:top-[-1px] data-[side=bottom]:rotate-180","data-[side=left]:right-[-1px] data-[side=left]:-rotate-90","data-[side=right]:left-[-1px] data-[side=right]:rotate-90"].join(" "),children:e("svg",{width:E,height:E/2,viewBox:"0 0 10 5","aria-hidden":"true",className:"block",children:e("path",{d:"M0 0h10L5 5z",fill:"var(--_mp-color-surface-container)"})})}):null,q||$?o("div",{className:"flex shrink-0 items-start gap-3",children:[o("div",{className:"flex min-w-0 flex-1 flex-col",children:[n(b)?e(t.Title,{className:`m-0 ${f[D]}`,children:b}):null,n(w)?e(t.Description,{className:`text-mp-on-surface-variant m-0 ${c}`,children:w}):null]}),$?o(t.Close,{"aria-label":B??_.close,className:["group text-mp-on-surface-variant relative flex size-8 shrink-0","rounded-mp-full -m-1 cursor-pointer items-center justify-center","appearance-none border-0 bg-transparent","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-2","focus-visible:outline-solid outline-none"].join(" "),children:[e(s,{}),e(i,{icon:a,size:18})]}):null]}):null,n(S)?e("div",{className:"min-w-0",children:S}):null]})})})]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import*as r from"react";import{Radio as i}from"@base-ui/react/radio";import{RadioGroup as n}from"@base-ui/react/radio-group";import{Field as l}from"@base-ui/react/field";import{accentSlots as o}from"../../internal/accent";import{MPStateLayer as t}from"../../internal/StateLayer";import{MPSupportingText as s}from"../../internal/SupportingText";import{META_TEXT as d,PROSE_TEXT as c,hasContent as p}from"../../internal/scale";const m={xs:{ring:"size-4",fill:"size-2",halo:"size-8"},sm:{ring:"size-[18px]",fill:"size-[9px]",halo:"size-9"},md:{ring:"size-5",fill:"size-2.5",halo:"size-10"},lg:{ring:"size-[22px]",fill:"size-[11px]",halo:"size-11"},xl:{ring:"size-6",fill:"size-3",halo:"size-12"}},u=r.createContext({size:"md",readOnly:!1,invalid:!1});export const MPRadio=r.forwardRef(function({value:n,label:o,description:s,disabled:f=!1,id:x},g){const h=r.useContext(u),b=m[h.size],y=r.useId(),z=x??`mp-radio-${y}`;return e(l.Root,{className:"mp-radio inline-block align-top",disabled:f,"data-mp-value":n,children:a("div",{className:["flex items-start gap-3",c[h.size]].join(" "),children:[e("span",{className:"flex h-[1lh] shrink-0 items-center",children:a(i.Root,{ref:g,id:z,value:n,disabled:f,className:["mp-radio__dot group relative inline-flex shrink-0 items-center justify-center","box-border rounded-full border-2 p-0","appearance-none bg-transparent font-[inherit] outline-none","transition-[border-color] duration-(--mp-sys-motion-duration-short4)",b.ring,f?"border-mp-on-surface/38 cursor-default":[h.readOnly?"cursor-default":"cursor-pointer",h.invalid?"border-mp-error":"border-mp-on-surface-variant","data-checked:border-(--_mp-accent)"].join(" ")].join(" "),children:[f?null:e(t,{layer:["top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full",b.halo,"bg-mp-on-surface","group-data-checked:bg-(--_mp-accent)"].join(" ")}),e(i.Indicator,{className:["rounded-full",b.fill,"transition-[opacity,scale] duration-(--mp-sys-motion-duration-short4)","ease-mp-standard","data-starting-style:scale-0 data-starting-style:opacity-0","data-ending-style:scale-0 data-ending-style:opacity-0",f?"bg-mp-on-surface/38":"bg-(--_mp-accent)"].join(" ")})]})}),p(o)||p(s)?a("span",{className:"flex min-w-0 flex-col gap-0.5",children:[p(o)?e(l.Label,{htmlFor:z,className:["leading-[1.4]",f?"text-mp-on-surface/38 cursor-default":h.readOnly?"text-mp-on-surface":"text-mp-on-surface cursor-pointer"].join(" "),children:o}):null,p(s)?e(l.Description,{className:`${d} text-mp-on-surface-variant data-disabled:text-mp-on-surface/38`,children:s}):null]}):null]})})});export const MPRadioGroup=r.forwardRef(function({value:i,defaultValue:t,onValueChange:c,label:m,description:f,errorMessage:x,orientation:g="vertical",size:h="md",color:b="primary",required:y=!1,disabled:z=!1,readOnly:v=!1,name:j,children:N},R){const O=p(x),k=O?"error":b,w=r.useId(),M=r.useMemo(()=>({size:h,readOnly:v,invalid:O}),[h,v,O]);return e(u.Provider,{value:M,children:a(l.Root,{className:"mp-radio-group flex flex-col gap-2",disabled:z,invalid:O,"data-mp-size":h,"data-mp-orientation":g,style:o(k),children:[p(m)?a("span",{id:w,className:[d,z?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:[m,y?e("span",{"aria-hidden":"true",children:" *"}):null]}):null,e(n,{ref:R,"aria-labelledby":p(m)?w:void 0,value:i,defaultValue:t,onValueChange:e=>c?.(String(e??"")),disabled:z,readOnly:v,required:y,name:j,className:["flex","horizontal"===g?"flex-row flex-wrap gap-x-6 gap-y-2":"flex-col gap-2"].join(" "),children:N}),e(s,{description:f,errorMessage:x})]})})});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type MPMessages } from '../../internal/i18n';
|
|
3
|
+
import type { MPColor, MPSize } from '../../types';
|
|
4
|
+
/** The words the control says on its own behalf. */
|
|
5
|
+
export type MPRatingLabels = MPMessages['rating'];
|
|
6
|
+
export interface MPRatingProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'color' | 'defaultValue' | 'onChange'> {
|
|
7
|
+
/** The score. Use with `onValueChange` for a controlled rating. */
|
|
8
|
+
value?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Where an uncontrolled rating starts.
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
defaultValue?: number;
|
|
14
|
+
/** Called with the new score. `0` is what a cleared rating reports. */
|
|
15
|
+
onValueChange?: (value: number) => void;
|
|
16
|
+
/**
|
|
17
|
+
* How many stars there are, and therefore the highest score.
|
|
18
|
+
* @default 5
|
|
19
|
+
*/
|
|
20
|
+
count?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The smallest step that can be *chosen*, as a fraction of one star — `0.5`
|
|
23
|
+
* gives half stars, `1` whole ones. Anything outside `0 < precision <= 1`
|
|
24
|
+
* falls back to `1`.
|
|
25
|
+
*
|
|
26
|
+
* It bounds what a reader can pick and nothing else. A `value` of `4.3` is
|
|
27
|
+
* drawn as four stars and a third at every precision, because an average is
|
|
28
|
+
* not a choice and rounding it to the nearest half would be reporting a
|
|
29
|
+
* different number from the one the component was handed.
|
|
30
|
+
* @default 1
|
|
31
|
+
*/
|
|
32
|
+
precision?: number;
|
|
33
|
+
/** The glyph a filled star is drawn with. */
|
|
34
|
+
icon?: React.ReactNode;
|
|
35
|
+
/** And the one an empty star is drawn with. It has to be the same shape. */
|
|
36
|
+
emptyIcon?: React.ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Choosing the score that is already chosen clears it back to `0`.
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
clearable?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Shows the score without letting it be changed — a product's average, a
|
|
44
|
+
* rating somebody else left.
|
|
45
|
+
*
|
|
46
|
+
* **This is the one `readOnly` in the library that does not drain the
|
|
47
|
+
* saturation.** It is not a control being held still: there are no inputs at
|
|
48
|
+
* all, and what is left is a picture of a number. A row of grey stars would
|
|
49
|
+
* say the score itself was unavailable.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
/** Unavailable. Drops the accent for the specification's disabled ink. */
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
/** Identifies the value when a form is submitted. */
|
|
56
|
+
name?: string;
|
|
57
|
+
/** A form will not submit until a star has been chosen. */
|
|
58
|
+
required?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* One star's height, on the glyph ladder. `md` is 24dp.
|
|
61
|
+
* @default 'md'
|
|
62
|
+
*/
|
|
63
|
+
size?: MPSize;
|
|
64
|
+
/**
|
|
65
|
+
* Which accent family the filled stars read.
|
|
66
|
+
* @default 'primary'
|
|
67
|
+
*/
|
|
68
|
+
color?: MPColor;
|
|
69
|
+
/**
|
|
70
|
+
* Which language the spoken names are written in — a BCP 47 tag such as `ko`,
|
|
71
|
+
* `pt-BR` or `zh-Hant`. Unsupported tags fall back to English.
|
|
72
|
+
*/
|
|
73
|
+
locale?: string;
|
|
74
|
+
/** Overrides for the words themselves. They win over the translation. */
|
|
75
|
+
labels?: Partial<MPRatingLabels>;
|
|
76
|
+
/**
|
|
77
|
+
* Publishes the score as schema.org `Rating` microdata, which is what a search
|
|
78
|
+
* engine reads to draw stars beside a result.
|
|
79
|
+
*
|
|
80
|
+
* `readOnly` only, and that is the whole of the rule: a score somebody is
|
|
81
|
+
* still choosing is not a fact about anything, and marking up an empty control
|
|
82
|
+
* as a rating of nought is telling a crawler something untrue about the page.
|
|
83
|
+
*
|
|
84
|
+
* ## It has to be placed inside what it rates
|
|
85
|
+
*
|
|
86
|
+
* Microdata is nesting, and this component cannot know what it is nested in —
|
|
87
|
+
* only the page does. So it emits the `Rating` and its three values, and the
|
|
88
|
+
* `itemProp` naming the relationship is yours to pass:
|
|
89
|
+
*
|
|
90
|
+
* ```tsx
|
|
91
|
+
* <div itemScope itemType="https://schema.org/Product">
|
|
92
|
+
* <h2 itemProp="name">A kettle</h2>
|
|
93
|
+
* <MPRating readOnly value={4.3} structuredData itemProp="aggregateRating" />
|
|
94
|
+
* </div>
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* `aggregateRating` also wants a `ratingCount` or a `reviewCount` beside it
|
|
98
|
+
* before a search engine will draw anything, and that number is the page's
|
|
99
|
+
* rather than this control's.
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
structuredData?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A score out of five, as a row of stars.
|
|
106
|
+
*
|
|
107
|
+
* Underneath an interactive rating is a radio group of real `<input>`s, one per
|
|
108
|
+
* choosable score, each visually hidden under the half of a star it stands for.
|
|
109
|
+
* That is the whole accessibility argument: a rating *is* "exactly one of
|
|
110
|
+
* these", so it gets one tab stop for the row, the arrow keys within it,
|
|
111
|
+
* `aria-checked` on the one that is taken and a value in a form submission —
|
|
112
|
+
* none of which a row of `<button>`s or a `<div>` with a click handler would
|
|
113
|
+
* have, and all of which the browser gives for free.
|
|
114
|
+
*
|
|
115
|
+
* The fraction is drawn by laying the filled star over the empty one and
|
|
116
|
+
* clipping it to a percentage of the width. Nothing is transformed and no glyph
|
|
117
|
+
* is scaled, so a half star is the left half of exactly the star beside it. The
|
|
118
|
+
* clip runs from the inline start, so it fills from the right under RTL with
|
|
119
|
+
* nothing being told to.
|
|
120
|
+
*
|
|
121
|
+
* `readOnly` is a different component in the same clothes: no inputs, no radio
|
|
122
|
+
* group, and one `role="img"` carrying the score as a sentence. A star display
|
|
123
|
+
* that kept twenty focusable radios would be twenty tab stops on a page that was
|
|
124
|
+
* only reporting a number.
|
|
125
|
+
*
|
|
126
|
+
* ## Why the stars are not amber
|
|
127
|
+
*
|
|
128
|
+
* Because there is no amber in this library's colour system. MD3 defines four
|
|
129
|
+
* accent families — `primary`, `secondary`, `tertiary` and `error` — and a fifth
|
|
130
|
+
* colour hardcoded here would be one the token sheet has no name for and a theme
|
|
131
|
+
* has no way to change. A product whose stars must be gold sets
|
|
132
|
+
* `--mp-sys-color-tertiary` to gold and asks for `color="tertiary"`, which is the
|
|
133
|
+
* same answer this library gives everywhere else.
|
|
134
|
+
*/
|
|
135
|
+
export declare const MPRating: React.ForwardRefExoticComponent<MPRatingProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as a from"react";import{MPIcon as i}from"../icon/MPIcon";import{StarIcon as n}from"../../constants/icons";import{accentSlots as r}from"../../internal/accent";import{fillMessage as o}from"../../internal/i18n";import{useMPLocale as l,useMPMessages as s}from"../../internal/locale";import{VISUALLY_HIDDEN as m}from"../../internal/visually-hidden";const c={xs:16,sm:20,md:24,lg:30,xl:36},d={xs:"gap-0.5",sm:"gap-0.5",md:"gap-1",lg:"gap-1",xl:"gap-1.5"};export const MPRating=a.forwardRef(function({value:u,defaultValue:p=0,onValueChange:h,count:f=5,precision:g=1,icon:x,emptyIcon:y,clearable:v=!0,readOnly:b=!1,disabled:j=!1,name:M,required:N=!1,size:P="md",color:w="primary",locale:S,labels:R,structuredData:_=!1,className:z,style:I,onPointerLeave:k,...q},C){const L=l(S),V=s("rating",L,R),A=a.useId(),B=M??A,[F,D]=a.useState(p),E=void 0!==u,O=E?u:F,[T,G]=a.useState(null),H=Math.max(1,Math.floor(f)),J=g>0&&g<=1?g:1,K=Math.round(1/J),Q=Math.max(0,Math.min(H,T??O)),U=e=>e<=0?V.empty:o(V.value,{value:String(e),max:String(H)}),W=e=>{E||D(e),h?.(e)},X=t=>{const a=e(i,{icon:n,size:c[P],className:t?"[&>svg]:fill-current":""});return(t?x:y)??a},Y=Array.from({length:H},(a,i)=>{const n=Math.max(0,Math.min(1,Q-i));return t("span",{className:["mp-rating__star relative inline-flex shrink-0","rounded-mp-xs",b||j?"":["outline-mp-secondary has-[:focus-visible]:outline-2","has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-solid"].join(" ")].filter(Boolean).join(" "),style:{width:c[P],height:c[P]},children:[e("span",{className:["flex items-center justify-center",j?"text-mp-on-surface/38":"text-mp-outline"].join(" "),style:{width:c[P],height:c[P]},children:X(!1)}),e("span",{"aria-hidden":"true",className:"mp-rating__fill pointer-events-none absolute inset-y-0 start-0 overflow-hidden",style:{width:100*n+"%"},children:e("span",{className:["flex items-center justify-center","transition-colors duration-(--mp-sys-motion-duration-short4)",j?"text-mp-on-surface/38":"text-(--_mp-accent)"].join(" "),style:{width:c[P],height:c[P]},children:X(!0)})}),b?null:Array.from({length:K},(t,a)=>{const n=Number((i+(a+1)*J).toFixed(4));return e("label",{className:["absolute inset-y-0",j?"":"cursor-pointer"].join(" "),style:{insetInlineStart:100*a/K+"%",width:100/K+"%"},onPointerEnter:()=>{j||G(n)},children:e("input",{type:"radio",className:m,name:B,value:n,checked:O===n,disabled:j,required:N,"aria-label":U(n),onChange:()=>W(n),onClick:()=>{v&&O===n&&W(0)}})},n)})]},i)}),Z=["mp-rating inline-flex items-center align-middle",d[P],z??""].filter(Boolean).join(" "),$={...r(w),...I};if(b){const i=Math.max(0,Math.min(H,O));return t("div",{ref:C,role:"img","data-mp-size":P,"aria-label":U(i),itemScope:_||void 0,itemType:_?"https://schema.org/Rating":void 0,className:Z,style:$,onPointerLeave:k,...q,children:[_?t(a.Fragment,{children:[e("meta",{itemProp:"ratingValue",content:String(i)}),e("meta",{itemProp:"bestRating",content:String(H)}),e("meta",{itemProp:"worstRating",content:"0"})]}):null,Y]})}return e("div",{ref:C,role:"radiogroup","data-mp-size":P,"aria-label":V.label,"aria-disabled":j||void 0,"aria-required":N||void 0,className:Z,style:$,onPointerLeave:e=>{G(null),k?.(e)},...q,children:Y})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{MPRating}from"./MPRating";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{Toggle as n}from"@base-ui/react/toggle";import{ToggleGroup as o}from"@base-ui/react/toggle-group";import{MPIcon as a}from"../icon/MPIcon";import{CheckIcon as i}from"../../constants/icons";import{MPStateLayer as s}from"../../internal/StateLayer";import{CONTROL_GAP as l,CONTROL_HEIGHT as d,CONTROL_ICON as c,CONTROL_PAD_X as u,CONTROL_TEXT as m}from"../../internal/scale";export const MPSegmentedButton=r.forwardRef(function({items:r,value:p,defaultValue:f,onValueChange:b,multiple:h=!1,showCheck:g=!0,size:x="md",fullWidth:y=!1,disabled:j=!1,"aria-label":v},w){return e(o,{ref:w,"aria-label":v,value:p,defaultValue:f,onValueChange:e=>b?.(e),multiple:h,disabled:j,"data-mp-size":x,className:["mp-segmented-button rounded-mp-full box-border items-center align-middle","overflow-hidden border",j?"border-mp-on-surface/12":"border-mp-outline",y?"flex w-full":"inline-flex w-fit",d[x]].join(" "),children:r.map((r,o)=>{const d=j||r.disabled;return t(n,{value:r.value,disabled:r.disabled,className:["mp-segmented-button__segment group relative flex h-full items-center","box-border justify-center bg-transparent font-[inherit] whitespace-nowrap","select-none","appearance-none overflow-hidden outline-none","transition-[background-color,color] duration-(--mp-sys-motion-duration-short4)",m[x],l[x],u[x],0===o?"":"border-s",d?"border-mp-on-surface/12 text-mp-on-surface/38 cursor-default":["border-mp-outline cursor-pointer","text-mp-on-surface","data-pressed:bg-mp-secondary-container","data-pressed:text-mp-on-secondary-container"].join(" "),y?"flex-1":""].filter(Boolean).join(" "),children:[d?null:e(s,{}),g||r.icon?t("span",{className:"relative flex shrink-0 items-center justify-center",style:{width:c[x],height:c[x]},children:[g?e("span",{className:["absolute inset-0 flex items-center justify-center opacity-0","transition-opacity duration-(--mp-sys-motion-duration-short4)","ease-mp-standard group-data-pressed:opacity-100"].join(" "),children:e(a,{icon:i,size:c[x]})}):null,r.icon?e("span",{className:["absolute inset-0 flex items-center justify-center","transition-opacity duration-(--mp-sys-motion-duration-short4)","ease-mp-standard",g?"group-data-pressed:opacity-0":""].filter(Boolean).join(" "),children:r.icon}):null]}):null,e("span",{className:"truncate",children:r.label})]},r.value)})})});
|
|
@@ -32,14 +32,31 @@ export interface MPSelectProps extends MPStyleProps {
|
|
|
32
32
|
defaultValue?: MPSelectValue | null;
|
|
33
33
|
/** Called with the newly chosen value — a value, not an event. */
|
|
34
34
|
onValueChange?: (value: MPSelectValue | null) => void;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Shown in the trigger while nothing is chosen.
|
|
37
|
+
*
|
|
38
|
+
* With a floating label it is held back until the label has risen out of its
|
|
39
|
+
* way, which is the moment the select is focused or opened. Two greyed strings
|
|
40
|
+
* in one box is not a hint, it is a collision.
|
|
41
|
+
*/
|
|
36
42
|
placeholder?: React.ReactNode;
|
|
37
43
|
/**
|
|
38
|
-
* Label in the outline's notch
|
|
39
|
-
* the
|
|
40
|
-
*
|
|
44
|
+
* Label for the select, drawn in the outline's notch and — while nothing is
|
|
45
|
+
* chosen, the popup is shut and there is no `startIcon` — resting on the
|
|
46
|
+
* trigger's own line where the placeholder would be. See `floatingLabel`.
|
|
41
47
|
*/
|
|
42
48
|
label?: React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the label rests on the trigger's line while there is nothing to make
|
|
51
|
+
* room for, and rises into the notch on focus or on the first choice.
|
|
52
|
+
*
|
|
53
|
+
* `false` pins it in the notch, which is the one thing a floating label costs:
|
|
54
|
+
* a select with a label and one without no longer sit at the same height in a
|
|
55
|
+
* form until both are answered. A `startIcon` holds the label up regardless —
|
|
56
|
+
* the icon is already standing where the resting label would be.
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
floatingLabel?: boolean;
|
|
43
60
|
/** The line under the control. Replaced by `errorMessage` when there is one. */
|
|
44
61
|
description?: React.ReactNode;
|
|
45
62
|
/**
|
|
@@ -58,8 +75,8 @@ export interface MPSelectProps extends MPStyleProps {
|
|
|
58
75
|
/** Name of the form control. */
|
|
59
76
|
name?: string;
|
|
60
77
|
/**
|
|
61
|
-
* The id put on the trigger and pointed at by the label.
|
|
62
|
-
*
|
|
78
|
+
* The id put on the trigger and pointed at by the label. Generated when it is
|
|
79
|
+
* left out.
|
|
63
80
|
*/
|
|
64
81
|
id?: string;
|
|
65
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as a}from"react/jsx-runtime";import*as t from"react";import{Select as n}from"@base-ui/react/select";import{Field as r}from"@base-ui/react/field";import{MPIcon as i}from"../icon/MPIcon";import{CheckIcon as l,ChevronDownIcon as o}from"../../constants/icons";import{MPFieldLabel as s,MPFieldOutline as c}from"../../internal/FieldOutline";import{MPSupportingText as
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import*as t from"react";import{Select as n}from"@base-ui/react/select";import{Field as r}from"@base-ui/react/field";import{MPIcon as i}from"../icon/MPIcon";import{CheckIcon as l,ChevronDownIcon as o}from"../../constants/icons";import{MPFieldLabel as s,MPFieldOutline as d,useFloatingLabel as c}from"../../internal/FieldOutline";import{MPStateLayer as m}from"../../internal/StateLayer";import{MPSupportingText as p}from"../../internal/SupportingText";import{CONTROL_ICON as u,PROSE_TEXT as f,hasContent as h}from"../../internal/scale";import{FADE as g,PORTAL_LAYER as x}from"../../internal/surface";const v={xs:{padding:"px-2",height:"h-8"},sm:{padding:"px-3",height:"h-10"},md:{padding:"px-4",height:"h-14"},lg:{padding:"px-4",height:"h-16"},xl:{padding:"px-5",height:"h-18"}};export const MPSelect=t.forwardRef(function({items:b,value:N,defaultValue:y,onValueChange:j,placeholder:w,label:I,floatingLabel:S=!0,description:k,errorMessage:z,startIcon:P,size:M="md",fullWidth:O=!1,required:V=!1,disabled:q=!1,readOnly:T=!1,name:_,id:C},L){const R=h(z),F=v[M],W=t.useId(),B=C??W,[A,D]=t.useState(y??null),[E,G]=t.useState(!1),H=void 0===N?A:N,{shrunk:J,focusProps:K}=c({floating:S&&h(I),filled:null!==H&&""!==H,pinned:E||!!P}),Q=t.useMemo(()=>b.map(e=>({label:e.label??String(e.value),value:e.value})),[b]);return a(r.Root,{className:["mp-select group flex-col align-top",O?"flex w-full":"inline-flex w-fit"].join(" "),disabled:q,invalid:R,"data-mp-size":M,...K,children:[a(n.Root,{id:B,name:_,items:Q,value:N,defaultValue:y,onValueChange:e=>{D(e??null),j?.(e??null)},onOpenChange:G,disabled:q,readOnly:T,required:V,children:[a("div",{className:"relative w-full",children:[a(n.Trigger,{ref:L,className:["relative flex w-full items-center gap-2 select-none","appearance-none bg-transparent font-[inherit] outline-none",F.padding,F.height,f[M],q?"text-mp-on-surface/38 cursor-default":"text-mp-on-surface "+(T?"cursor-default":"cursor-pointer")].join(" "),children:[P?e("span",{className:["flex shrink-0 items-center",q?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:P}):null,e(n.Value,{className:["min-w-0 flex-1 truncate text-start","data-placeholder:text-mp-on-surface-variant",q?"data-placeholder:text-mp-on-surface/38":""].filter(Boolean).join(" "),placeholder:J?w:void 0}),e(n.Icon,{className:["flex shrink-0 items-center","transition-transform duration-(--mp-sys-motion-duration-short4)","data-popup-open:rotate-180",q?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:e(i,{icon:o,size:u[M]})})]}),e(d,{label:I,required:V,notched:J}),h(I)?e(s,{size:M,label:I,required:V,htmlFor:B,shrunk:J}):null]}),e(n.Portal,{children:e(n.Positioner,{className:x,sideOffset:4,alignItemWithTrigger:!1,children:e(n.Popup,{className:["mp-select__popup rounded-mp-xs shadow-mp-2 bg-mp-surface-container p-2","text-mp-on-surface min-w-[var(--anchor-width)] outline-none",f[M],g].join(" "),children:e(n.List,{className:"max-h-[min(20rem,var(--available-height))] overflow-y-auto overscroll-contain",children:b.map(t=>a(n.Item,{value:t.value,disabled:t.disabled,className:["mp-select__item group rounded-mp-xs relative flex cursor-pointer items-center","gap-3 py-2 pe-3 ps-2 select-none outline-none","transition-[background-color,color]","duration-(--mp-sys-motion-duration-short4)","data-selected:text-mp-on-secondary-container","data-selected:bg-mp-secondary-container","data-disabled:text-mp-on-surface/38 data-disabled:cursor-default"].join(" "),children:[e(m,{className:"group-data-highlighted:opacity-8 group-data-disabled:opacity-0"}),e("span",{className:"flex size-5 shrink-0 items-center justify-center",children:e(n.ItemIndicator,{children:e(i,{icon:l,size:18})})}),e(n.ItemText,{className:"min-w-0 flex-1 truncate",children:t.label??String(t.value)})]},String(t.value)))})})})})]}),e(p,{description:k,errorMessage:z,className:F.padding})]})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import*as r from"react";import{useRender as l}from"@base-ui/react/use-render";import{CONTROL_SQUARE as o}from"../../internal/scale";const a={xs:"h-3",sm:"h-3.5",md:"h-4",lg:"h-4",xl:"h-5.5"},n={xs:"gap-1",sm:"gap-1.5",md:"gap-2",lg:"gap-2",xl:"gap-1.5"},i={xs:"h-12",sm:"h-16",md:"h-20",lg:"h-28",xl:"h-36"},t="overflow-hidden bg-(--_mp-placeholder)";function s(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}export const MPSkeleton=r.forwardRef(function({shape:r="line",lines:m=1,size:d="md",color:p,width:c,height:h,animated:f=!0,label:u,render:x,className:g,style:w,...
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import*as r from"react";import{useRender as l}from"@base-ui/react/use-render";import{CONTROL_SQUARE as o}from"../../internal/scale";const a={xs:"h-3",sm:"h-3.5",md:"h-4",lg:"h-4",xl:"h-5.5"},n={xs:"gap-1",sm:"gap-1.5",md:"gap-2",lg:"gap-2",xl:"gap-1.5"},i={xs:"h-12",sm:"h-16",md:"h-20",lg:"h-28",xl:"h-36"},t="overflow-hidden bg-(--_mp-placeholder)";function s(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}export const MPSkeleton=r.forwardRef(function({shape:r="line",lines:m=1,size:d="md",color:p,width:c,height:h,animated:f=!0,label:u,render:x,className:g,style:w,...v},b){const y=f?"animate-pulse motion-reduce:animate-none":"",$="circle"===r?`rounded-mp-full shrink-0 ${o[d]}`:"rect"===r?`rounded-mp-md w-full ${void 0===h?i[d]:""}`:`rounded-mp-xs w-full ${a[d]}`,j=u?{role:"status","aria-busy":!0,"aria-label":u}:{"aria-hidden":!0},k="line"===r&&m>1;return l({render:x,ref:b,props:{"data-mp-size":d,className:(k?["mp-skeleton flex w-full flex-col",n[d],g??""]:["mp-skeleton",t,y,$,g??""]).filter(Boolean).join(" "),style:{"--_mp-placeholder":p?`var(--_mp-color-${p}-container)`:"var(--_mp-color-surface-container-highest)",width:s(c),height:k?void 0:s(h),...w},...j,...k?{children:Array.from({length:m},(r,l)=>e("div",{className:[t,y,"rounded-mp-xs",a[d],l===m-1?"w-3/5":"w-full"].filter(Boolean).join(" ")},l))}:null,...v}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as r}from"react/jsx-runtime";import*as s from"react";import{Slider as a}from"@base-ui/react/slider";import{accentSlots as t}from"../../internal/accent";import{MPStateLayer as n}from"../../internal/StateLayer";import{META_TEXT as i,hasContent as o}from"../../internal/scale";const l={xs:{thickness:"h-0.5",cross:"w-0.5",handle:"size-3.5",strip:"h-8",stripCross:"w-8"},sm:{thickness:"h-[3px]",cross:"w-[3px]",handle:"size-4",strip:"h-9",stripCross:"w-9"},md:{thickness:"h-1",cross:"w-1",handle:"size-5",strip:"h-10",stripCross:"w-10"},lg:{thickness:"h-1.5",cross:"w-1.5",handle:"size-6",strip:"h-11",stripCross:"w-11"},xl:{thickness:"h-2",cross:"w-2",handle:"size-7",strip:"h-12",stripCross:"w-12"}},c=["duration-(--mp-sys-motion-duration-short2) ease-mp-standard","motion-reduce:transition-none"].join(" "),m={xs:"size-8",sm:"size-9",md:"size-10",lg:"size-11",xl:"size-12"};export const MPSlider=s.forwardRef(function({value:s,defaultValue:u,onValueChange:p,onValueCommitted:d,min:f=0,max:h=100,step:g=1,label:x,description:b,showValue:w=!1,format:j,orientation:y="horizontal",size:z="md",color:v="primary",disabled:C=!1,name:N,"aria-label":_},k){const V="vertical"===y,$=l[z],A=s??u,B=Array.isArray(A)?A.length:1;return r(a.Root,{ref:k,value:s,defaultValue:u,onValueChange:e=>p?.(e),onValueCommitted:e=>d?.(e),min:f,max:h,step:g,disabled:C,orientation:y,format:j,name:N,"data-mp-size":z,className:["mp-slider flex",V?"w-fit flex-col items-center gap-2":"w-full flex-col gap-1",C?"cursor-default":""].filter(Boolean).join(" "),style:t(v),children:[o(x)||w?r("div",{className:["flex w-full items-baseline gap-2",i].join(" "),children:[o(x)?e(a.Label,{className:C?"text-mp-on-surface/38":"text-mp-on-surface-variant",children:x}):null,w?e(a.Value,{className:["ms-auto tabular-nums",C?"text-mp-on-surface/38":"text-mp-on-surface"].join(" ")}):null]}):null,e(a.Control,{className:["mp-slider__control group/rail flex touch-none items-center justify-center select-none",V?`${$.stripCross} h-40 flex-col`:`w-full ${$.strip}`,C?"":"cursor-pointer"].filter(Boolean).join(" "),children:r(a.Track,{className:["mp-slider__track rounded-mp-full relative",V?`${$.cross} h-full`:`${$.thickness} w-full`,C?"bg-mp-on-surface/12":"bg-mp-surface-container-highest"].join(" "),children:[e(a.Indicator,{className:["rounded-mp-full","[transition-property:inset-inline-start,width,bottom,height]",c,"group-data-dragging/rail:transition-none",C?"bg-mp-on-surface/38":"bg-(--_mp-accent)"].join(" ")}),Array.from({length:B},(r,s)=>e(a.Thumb,{index:s,"aria-label":o(x)?void 0:_,className:["mp-slider__handle group rounded-mp-full relative outline-none","[transition-property:inset-inline-start,bottom]",c,"data-dragging:transition-none",$.handle,C?"bg-mp-on-surface/38 cursor-default":"bg-(--_mp-accent) cursor-grab active:cursor-grabbing"].join(" "),children:C?null:e(n,{layer:["top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full",m[z],"bg-(--_mp-accent)"].join(" "),className:"group-data-dragging:opacity-16"})},s))]})}),o(b)?e("div",{className:[i,C?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:b}):null]})});
|
|
@@ -114,10 +114,15 @@ export interface MPSnackbarProviderProps {
|
|
|
114
114
|
*/
|
|
115
115
|
showClose?: boolean;
|
|
116
116
|
/**
|
|
117
|
-
* Accessible name of every snackbar's × button.
|
|
118
|
-
*
|
|
117
|
+
* Accessible name of every snackbar's × button. Defaults to the word for
|
|
118
|
+
* "close" in `locale`.
|
|
119
119
|
*/
|
|
120
120
|
closeLabel?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Which language the × button's default name is written in. Falls back to the
|
|
123
|
+
* nearest `MPLocaleProvider`, then to English.
|
|
124
|
+
*/
|
|
125
|
+
locale?: string;
|
|
121
126
|
children?: React.ReactNode;
|
|
122
127
|
}
|
|
123
128
|
/**
|
|
@@ -167,4 +172,4 @@ export declare function useMPSnackbar(): {
|
|
|
167
172
|
* is not part of Material Design 3 — so a `Toast` here would be a different
|
|
168
173
|
* component wearing the name of one the specification still ships.
|
|
169
174
|
*/
|
|
170
|
-
export declare function MPSnackbarProvider({ color, position, timeout, limit, width, size, showClose, closeLabel, children }: MPSnackbarProviderProps): React.JSX.Element;
|
|
175
|
+
export declare function MPSnackbarProvider({ color, position, timeout, limit, width, size, showClose, closeLabel, locale: localeProp, children }: MPSnackbarProviderProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as o from"react";import{Toast as s}from"@base-ui/react/toast";import{MPIcon as i}from"../icon/MPIcon";import{CloseIcon as n}from"../../constants/icons";import{accentSlots as r}from"../../internal/accent";import{useMPLocale as a,useMPMessages as l}from"../../internal/locale";import{MPStateLayer as c}from"../../internal/StateLayer";import{PORTAL_LAYER as m}from"../../internal/surface";const p={"top-start":"top-0 items-start","top-center":"top-0 items-center","top-end":"top-0 items-end","bottom-start":"bottom-0 flex-col-reverse items-start","bottom-center":"bottom-0 flex-col-reverse items-center","bottom-end":"bottom-0 flex-col-reverse items-end"},d=["transition-[opacity,translate] duration-(--mp-sys-motion-duration-short4)","ease-mp-standard","data-starting-style:opacity-0 data-ending-style:opacity-0"].join(" "),u={top:"motion-safe:data-starting-style:-translate-y-full motion-safe:data-ending-style:-translate-y-full",bottom:"motion-safe:data-starting-style:translate-y-full motion-safe:data-ending-style:translate-y-full"},f={xs:"text-mp-body-small",sm:"text-mp-body-small",md:"text-mp-body-medium",lg:"text-mp-body-medium",xl:"text-mp-body-large"},x={xs:"min-h-9 gap-1.5 py-1.5 ps-3 pe-1.5",sm:"min-h-10 gap-2 py-2 ps-3.5 pe-2",md:"min-h-12 gap-2 py-2.5 ps-4 pe-2",lg:"min-h-14 gap-3 py-3 ps-5 pe-2.5",xl:"min-h-16 gap-3 py-3.5 pe-3 ps-6"},b={xs:16,sm:18,md:20,lg:22,xl:24};function y(e){const{color:t,icon:o,message:s,actionLabel:i,onAction:n,...r}=e;return{...r,title:s,data:{color:t,icon:o},actionProps:void 0===i?void 0:{children:i,onClick:n}}}export function useMPSnackbar(){const e=s.useToastManager();return o.useMemo(()=>({add:t=>e.add(y(t)),close:t=>e.close(t),update:(t,o)=>e.update(t,y(o)),promise:(t,o)=>e.promise(t,{loading:y(o.loading),success:e=>y("function"==typeof o.success?o.success(e):o.success),error:e=>y("function"==typeof o.error?o.error(e):o.error)}),snackbars:e.toasts}),[e])}function h({toast:o,color:a,size:l,showClose:m,closeLabel:p,swipeDirection:y,edge:h}){const g=o.data?.color??a,v=o.data?.icon,w={"--_mp-plate":g?`var(--_mp-color-${g}-container)`:"var(--_mp-color-inverse-surface)","--_mp-on-plate":g?`var(--_mp-color-on-${g}-container)`:"var(--_mp-color-inverse-on-surface)","--_mp-plate-action":g?`var(--_mp-color-${g})`:"var(--_mp-color-inverse-primary)",...g?r(g):null};return t(s.Root,{toast:o,swipeDirection:y,"data-mp-size":l,className:["mp-snackbar rounded-mp-xs shadow-mp-3 pointer-events-auto flex w-full items-center","bg-(--_mp-plate) text-(--_mp-on-plate) outline-none",x[l],f[l],d,u[h],"data-limited:hidden"].join(" "),style:w,children:[v?e("span",{className:"flex shrink-0 items-center",children:v}):null,e(s.Title,{render:e("span",{}),className:"min-w-0 flex-1 py-0.5 ps-1 [min-inline-size:min(280px,100%)]"}),e(s.Action,{className:["text-mp-label-large flex shrink-0 cursor-pointer items-center","rounded-mp-full h-8 px-3 text-(--_mp-plate-action)","transition-colors duration-(--mp-sys-motion-duration-short4)","hover:bg-(--_mp-plate-action)/8 focus-visible:bg-(--_mp-plate-action)/10","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-2","focus-visible:outline-solid outline-none"].join(" ")}),m?t(s.Close,{"aria-label":p,className:["group rounded-mp-full relative flex size-8 shrink-0 cursor-pointer","items-center justify-center text-(--_mp-on-plate)","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-2","focus-visible:outline-solid outline-none"].join(" "),children:[e(c,{}),e(i,{icon:n,size:b[l]})]}):null]})}function g({position:t,width:o,...i}){const{toasts:n}=s.useToastManager(),r=t.startsWith("top")?"top":"bottom",a=["top"===r?"up":"down","left","right"];return e(s.Portal,{children:e(s.Viewport,{className:[m,"pointer-events-none fixed inset-x-0 flex flex-col gap-2 p-4",p[t]].join(" "),children:n.map(t=>e("div",{className:"w-full",style:{maxWidth:"number"==typeof o?`${o}px`:o},children:e(h,{toast:t,swipeDirection:a,edge:r,...i})},t.id))})})}export function MPSnackbarProvider({color:o,position:i="bottom-start",timeout:n=5e3,limit:r=3,width:c=600,size:m="md",showClose:p=!0,closeLabel:d,locale:u,children:f}){const x=a(u),b=l("common",x);return t(s.Provider,{timeout:n,limit:r,children:[f,e(g,{position:i,width:c,color:o,size:m,showClose:p,closeLabel:d??b.close})]})}
|