@12-apps/ui 6.2.0 → 6.3.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/{chunk-35VGGLOC.js → chunk-CEKPLUQV.js} +2 -2
- package/dist/{chunk-35VGGLOC.js.map → chunk-CEKPLUQV.js.map} +1 -1
- package/dist/{chunk-62XQWGXU.js → chunk-MXPXKORR.js} +19 -17
- package/dist/chunk-MXPXKORR.js.map +1 -0
- package/dist/{chunk-7XLEWBKL.js → chunk-N554AFDB.js} +7 -10
- package/dist/chunk-N554AFDB.js.map +1 -0
- package/dist/{chunk-JDO7W4D4.js → chunk-R5ZQZSEQ.js} +2 -20
- package/dist/{chunk-JDO7W4D4.js.map → chunk-R5ZQZSEQ.js.map} +1 -1
- package/dist/{chunk-R4TYXKDD.js → chunk-TPQRIPCN.js} +52 -48
- package/dist/chunk-TPQRIPCN.js.map +1 -0
- package/dist/copy.js +1 -0
- package/dist/copy.js.map +1 -0
- package/dist/data-display/CardKit.js +15 -4
- package/dist/data-display/CardKit.js.map +1 -1
- package/dist/data-display/DataViews.js +664 -616
- package/dist/data-display/DataViews.js.map +1 -1
- package/dist/data-display/SectionOnboarding.js +3 -3
- package/dist/data-display/SectionOnboarding.js.map +1 -1
- package/dist/feedback/ConfirmAction.js +3 -5
- package/dist/form/CategorySelect.js +1 -1
- package/dist/form/CepField.js +1 -1
- package/dist/form/total-form.js +8 -4
- package/dist/form/total-form.js.map +1 -1
- package/dist/layout/ContentToolbar.js +1 -1
- package/dist/layout/TableFilter.js +1 -1
- package/dist/pt-BR.js +222 -0
- package/dist/pt-BR.js.map +1 -0
- package/dist/types/components/data-display/CardKit/use-remove-confirm.d.ts +4 -1
- package/dist/types/components/data-display/CardKit/use-remove-confirm.d.ts.map +1 -1
- package/dist/types/components/data-display/CardKit/use-row-confirm.d.ts +5 -2
- package/dist/types/components/data-display/CardKit/use-row-confirm.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/DataViewsBoard.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/DeleteViewDialog.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/ManageViewsDialog.d.ts +4 -1
- package/dist/types/components/data-display/DataViews/ManageViewsDialog.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/SaveViewModal.d.ts +0 -5
- package/dist/types/components/data-display/DataViews/SaveViewModal.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/base-card.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/base-list-card-gutters.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-bar-controls.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-category-pill.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-columns-tab.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-copy-context.d.ts +17 -0
- package/dist/types/components/data-display/DataViews/data-views-copy-context.d.ts.map +1 -0
- package/dist/types/components/data-display/DataViews/data-views-copy.d.ts +205 -0
- package/dist/types/components/data-display/DataViews/data-views-copy.d.ts.map +1 -0
- package/dist/types/components/data-display/DataViews/data-views-display-panel.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-display-tabs.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-export.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-filter-panel.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-grid-helpers.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-more-fields.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-more-filters.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-range-pill.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-range-presets.d.ts +3 -2
- package/dist/types/components/data-display/DataViews/data-views-range-presets.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-scopes.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-search.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-select-all-strip.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-table-parts.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/data-views-view-nav.d.ts +1 -1
- package/dist/types/components/data-display/DataViews/data-views-view-nav.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/index.d.ts +2 -0
- package/dist/types/components/data-display/DataViews/index.d.ts.map +1 -1
- package/dist/types/components/data-display/DataViews/save-view-preview.d.ts +10 -0
- package/dist/types/components/data-display/DataViews/save-view-preview.d.ts.map +1 -0
- package/dist/types/components/data-display/DataViews/use-saved-views-controller.d.ts.map +1 -1
- package/dist/types/components/data-display/SectionOnboarding/SectionOnboarding.types.d.ts +6 -5
- package/dist/types/components/data-display/SectionOnboarding/SectionOnboarding.types.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.hooks.d.ts +1 -3
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.hooks.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.parts.d.ts +4 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.parts.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.types.d.ts +9 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmAction.types.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmButton.d.ts +2 -1
- package/dist/types/components/feedback/ConfirmAction/ConfirmButton.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/index.d.ts +2 -2
- package/dist/types/components/feedback/ConfirmAction/index.d.ts.map +1 -1
- package/dist/types/components/feedback/ConfirmAction/with-confirmation.d.ts +5 -1
- package/dist/types/components/feedback/ConfirmAction/with-confirmation.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategoryPanel.d.ts +4 -1
- package/dist/types/components/form/CategorySelect/CategoryPanel.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategoryPanelFoot.d.ts +5 -2
- package/dist/types/components/form/CategorySelect/CategoryPanelFoot.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategoryPanelHead.d.ts +5 -2
- package/dist/types/components/form/CategorySelect/CategoryPanelHead.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategoryPanelList.d.ts +3 -0
- package/dist/types/components/form/CategorySelect/CategoryPanelList.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategorySelect.types.d.ts +5 -0
- package/dist/types/components/form/CategorySelect/CategorySelect.types.d.ts.map +1 -1
- package/dist/types/components/form/CategorySelect/CategoryTrigger.d.ts +4 -1
- package/dist/types/components/form/CategorySelect/CategoryTrigger.d.ts.map +1 -1
- package/dist/types/components/form/CepField/CepField.d.ts +1 -1
- package/dist/types/components/form/CepField/CepField.d.ts.map +1 -1
- package/dist/types/components/form/CepField/CepField.types.d.ts +3 -0
- package/dist/types/components/form/CepField/CepField.types.d.ts.map +1 -1
- package/dist/types/components/form/total-form/Fields/CategoryField.d.ts +4 -1
- package/dist/types/components/form/total-form/Fields/CategoryField.d.ts.map +1 -1
- package/dist/types/components/form/total-form/Fields/CepField.d.ts +4 -1
- package/dist/types/components/form/total-form/Fields/CepField.d.ts.map +1 -1
- package/dist/types/components/layout/ContentToolbar/ContentToolbar.types.d.ts +6 -1
- package/dist/types/components/layout/ContentToolbar/ContentToolbar.types.d.ts.map +1 -1
- package/dist/types/components/layout/ContentToolbar/SavedViewsMenu.d.ts.map +1 -1
- package/dist/types/copy.d.ts +99 -0
- package/dist/types/copy.d.ts.map +1 -0
- package/dist/types/pt-BR.d.ts +28 -0
- package/dist/types/pt-BR.d.ts.map +1 -0
- package/package.json +10 -2
- package/src/components/data-display/CardKit/use-remove-confirm.tsx +5 -0
- package/src/components/data-display/CardKit/use-row-confirm.tsx +7 -2
- package/src/components/data-display/DataViews/DataViewsBoard.tsx +7 -4
- package/src/components/data-display/DataViews/DeleteViewDialog.tsx +6 -4
- package/src/components/data-display/DataViews/ManageViewsDialog.tsx +26 -10
- package/src/components/data-display/DataViews/SaveViewModal.tsx +56 -90
- package/src/components/data-display/DataViews/base-card.tsx +3 -1
- package/src/components/data-display/DataViews/base-list-card-gutters.tsx +3 -1
- package/src/components/data-display/DataViews/data-views-bar-controls.tsx +8 -5
- package/src/components/data-display/DataViews/data-views-category-pill.tsx +6 -3
- package/src/components/data-display/DataViews/data-views-columns-tab.tsx +5 -3
- package/src/components/data-display/DataViews/data-views-copy-context.tsx +43 -0
- package/src/components/data-display/DataViews/data-views-copy.ts +214 -0
- package/src/components/data-display/DataViews/data-views-display-panel.tsx +15 -9
- package/src/components/data-display/DataViews/data-views-display-tabs.tsx +19 -29
- package/src/components/data-display/DataViews/data-views-export.tsx +9 -10
- package/src/components/data-display/DataViews/data-views-filter-panel.tsx +9 -5
- package/src/components/data-display/DataViews/data-views-grid-helpers.tsx +5 -2
- package/src/components/data-display/DataViews/data-views-more-fields.tsx +5 -3
- package/src/components/data-display/DataViews/data-views-more-filters.tsx +6 -3
- package/src/components/data-display/DataViews/data-views-range-pill.tsx +9 -5
- package/src/components/data-display/DataViews/data-views-range-presets.ts +7 -8
- package/src/components/data-display/DataViews/data-views-scopes.tsx +3 -1
- package/src/components/data-display/DataViews/data-views-search.tsx +7 -4
- package/src/components/data-display/DataViews/data-views-select-all-strip.tsx +5 -3
- package/src/components/data-display/DataViews/data-views-table-parts.tsx +7 -2
- package/src/components/data-display/DataViews/data-views-view-nav.tsx +22 -16
- package/src/components/data-display/DataViews/index.ts +20 -0
- package/src/components/data-display/DataViews/save-view-preview.tsx +78 -0
- package/src/components/data-display/DataViews/use-saved-views-controller.ts +3 -1
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.tsx +3 -3
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.types.ts +8 -7
- package/src/components/feedback/ConfirmAction/ConfirmAction.hooks.ts +2 -2
- package/src/components/feedback/ConfirmAction/ConfirmAction.parts.tsx +12 -5
- package/src/components/feedback/ConfirmAction/ConfirmAction.types.ts +9 -1
- package/src/components/feedback/ConfirmAction/ConfirmButton.tsx +12 -4
- package/src/components/feedback/ConfirmAction/index.ts +2 -2
- package/src/components/feedback/ConfirmAction/with-confirmation.tsx +4 -3
- package/src/components/form/CategorySelect/CategoryPanel.tsx +18 -6
- package/src/components/form/CategorySelect/CategoryPanelFoot.tsx +10 -5
- package/src/components/form/CategorySelect/CategoryPanelHead.tsx +8 -3
- package/src/components/form/CategorySelect/CategoryPanelList.tsx +17 -10
- package/src/components/form/CategorySelect/CategorySelect.tsx +3 -3
- package/src/components/form/CategorySelect/CategorySelect.types.ts +5 -0
- package/src/components/form/CategorySelect/CategoryTrigger.tsx +5 -1
- package/src/components/form/CepField/CepField.tsx +6 -9
- package/src/components/form/CepField/CepField.types.ts +3 -0
- package/src/components/form/total-form/Fields/CategoryField.tsx +5 -0
- package/src/components/form/total-form/Fields/CepField.tsx +5 -0
- package/src/components/layout/ContentToolbar/ContentToolbar.types.ts +6 -1
- package/src/components/layout/ContentToolbar/SavedViewsMenu.tsx +1 -21
- package/src/components/layout/TableFilter/TableFilter.tsx +1 -1
- package/src/copy.ts +103 -0
- package/src/pt-BR.ts +247 -0
- package/dist/chunk-62XQWGXU.js.map +0 -1
- package/dist/chunk-7XLEWBKL.js.map +0 -1
- package/dist/chunk-R4TYXKDD.js.map +0 -1
|
@@ -263,7 +263,7 @@ var TableFilterRangeField = ({
|
|
|
263
263
|
step,
|
|
264
264
|
minPlaceholder = "min",
|
|
265
265
|
maxPlaceholder = "max",
|
|
266
|
-
invalidLabel
|
|
266
|
+
invalidLabel,
|
|
267
267
|
testId
|
|
268
268
|
}) => {
|
|
269
269
|
const invalid = isRangeInverted(value);
|
|
@@ -324,4 +324,4 @@ export {
|
|
|
324
324
|
useTableFilterContext,
|
|
325
325
|
TableFilter
|
|
326
326
|
};
|
|
327
|
-
//# sourceMappingURL=chunk-
|
|
327
|
+
//# sourceMappingURL=chunk-CEKPLUQV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/layout/TableFilter/TableFilter.tsx","../src/components/layout/TableFilter/TableFilterContext.tsx"],"sourcesContent":["'use client';\n\nimport CloseIcon from '@mui/icons-material/Close';\nimport SearchIcon from '@mui/icons-material/Search';\nimport {\n Box,\n Checkbox,\n Divider,\n FormControlLabel,\n IconButton,\n InputAdornment,\n Link,\n TextField,\n Typography,\n} from '@mui/material';\nimport React, { useRef, useState } from 'react';\n\nimport { TableFilterContext, useTableFilterContext } from './TableFilterContext';\nimport type {\n TableFilterCheckboxFieldProps,\n TableFilterKeywordProps,\n TableFilterLayoutProps,\n TableFilterMainProps,\n TableFilterPanelProps,\n TableFilterProps,\n TableFilterRangeFieldProps,\n TableFilterSectionProps,\n} from './TableFilter.types';\n\nconst PANEL_WIDTH = 280;\n\n/**\n * Compound filter-panel system, MUI port of the reference `TableFilter`. Provides\n * open/close state; `Panel` slides in from the right beside `Main` (no overlap).\n *\n * @example\n * ```tsx\n * <TableFilter open={open} onOpenChange={setOpen} hasActiveFilters={n > 0}>\n * <TableFilter.Layout>\n * <TableFilter.Main>{table}</TableFilter.Main>\n * <TableFilter.Panel onClearAll={clearAll}>\n * <TableFilter.Keyword value={q} onChange={setQ} />\n * <TableFilter.Section title=\"Attributes\">\n * <TableFilter.CheckboxField label=\"Category\" options={cats} selected={sel} onToggle={toggle} />\n * <TableFilter.RangeField label=\"Price\" unit=\"R$\" value={price} onChange={setPrice} />\n * </TableFilter.Section>\n * </TableFilter.Panel>\n * </TableFilter.Layout>\n * </TableFilter>\n * ```\n */\nexport function TableFilter({\n children,\n open,\n onOpenChange,\n hasActiveFilters = false,\n}: TableFilterProps): React.JSX.Element {\n return (\n <TableFilterContext.Provider value={{ open, onOpenChange, hasActiveFilters }}>\n {children}\n </TableFilterContext.Provider>\n );\n}\nTableFilter.displayName = 'TableFilter';\n\nconst TableFilterLayout = ({ children, className }: TableFilterLayoutProps): React.JSX.Element => {\n const { open } = useTableFilterContext();\n return (\n <Box\n className={className}\n sx={{\n display: 'flex',\n minHeight: 0,\n minWidth: 0,\n flex: 1,\n alignItems: 'stretch',\n overflow: 'hidden',\n gap: open ? 2 : 0,\n }}\n >\n {children}\n </Box>\n );\n};\nTableFilterLayout.displayName = 'TableFilter.Layout';\n\nconst TableFilterMain = ({ children, className }: TableFilterMainProps): React.JSX.Element => (\n <Box className={className} sx={{ minWidth: 0, flex: 1, overflowY: 'auto', overflowX: 'hidden' }}>\n {children}\n </Box>\n);\nTableFilterMain.displayName = 'TableFilter.Main';\n\nconst TableFilterPanel = ({\n children,\n onClearAll,\n ariaLabel = 'Filters',\n clearTestId,\n}: TableFilterPanelProps): React.JSX.Element => {\n const { open } = useTableFilterContext();\n return (\n <Box\n component=\"aside\"\n aria-label={ariaLabel}\n aria-hidden={!open}\n sx={{\n display: 'flex',\n minHeight: 0,\n flexShrink: 0,\n flexDirection: 'column',\n alignSelf: 'stretch',\n overflow: 'hidden',\n bgcolor: 'background.paper',\n width: open ? PANEL_WIDTH : 0,\n borderLeft: open ? 1 : 0,\n borderColor: 'divider',\n transition: 'width 300ms ease-in-out',\n '@media (prefers-reduced-motion: reduce)': { transition: 'none' },\n }}\n >\n <Box\n sx={{\n display: 'flex',\n minHeight: 0,\n flex: 1,\n flexDirection: 'column',\n overflowY: 'auto',\n overflowX: 'hidden',\n visibility: open ? 'visible' : 'hidden',\n opacity: open ? 1 : 0,\n pointerEvents: open ? 'auto' : 'none',\n transition: 'opacity 200ms ease-out',\n }}\n >\n <Box sx={{ boxSizing: 'border-box', display: 'flex', width: '100%', minWidth: 0, flexDirection: 'column', gap: 2.5, p: 2 }}>\n <Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>\n <Link\n component=\"button\"\n type=\"button\"\n underline=\"hover\"\n data-testid={clearTestId}\n onClick={onClearAll}\n sx={{ fontSize: '0.75rem', color: 'text.secondary' }}\n >\n Clear All Filters\n </Link>\n </Box>\n {children}\n </Box>\n </Box>\n </Box>\n );\n};\nTableFilterPanel.displayName = 'TableFilter.Panel';\n\nconst TableFilterKeyword = ({\n value,\n onChange,\n placeholder = 'Press Enter to filter',\n label = 'Filter by keyword',\n testId,\n}: TableFilterKeywordProps): React.JSX.Element => {\n const [draft, setDraft] = useState(value);\n const prevValue = useRef(value);\n if (prevValue.current !== value) {\n prevValue.current = value;\n if (draft !== value) setDraft(value);\n }\n\n const commit = (): void => {\n if (draft !== value) onChange(draft);\n };\n const clearKeyword = (): void => {\n setDraft('');\n if (value !== '') onChange('');\n };\n\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <Typography component=\"label\" sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>\n {label}\n </Typography>\n <TextField\n size=\"small\"\n name=\"keyword\"\n placeholder={placeholder}\n value={draft}\n onChange={(event) => setDraft(event.target.value)}\n onBlur={commit}\n onKeyDown={(event) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n commit();\n }}\n inputProps={{ 'aria-label': label, 'data-testid': testId }}\n InputProps={{\n startAdornment: (\n <InputAdornment position=\"start\">\n <SearchIcon sx={{ fontSize: 16, color: 'text.secondary' }} />\n </InputAdornment>\n ),\n endAdornment:\n draft !== '' ? (\n <InputAdornment position=\"end\">\n <IconButton\n size=\"small\"\n aria-label=\"Clear keyword filter\"\n data-testid={testId ? `${testId}-clear` : undefined}\n onMouseDown={(event) => event.preventDefault()}\n onClick={clearKeyword}\n >\n <CloseIcon sx={{ fontSize: 16 }} />\n </IconButton>\n </InputAdornment>\n ) : null,\n }}\n />\n </Box>\n );\n};\nTableFilterKeyword.displayName = 'TableFilter.Keyword';\n\nconst TableFilterSection = ({ title, children }: TableFilterSectionProps): React.JSX.Element => (\n <Box>\n <Divider sx={{ mb: 2.5 }} />\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>\n <Typography component=\"h2\" sx={{ fontSize: '0.875rem', fontWeight: 600, color: 'text.primary' }}>\n {title}\n </Typography>\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>{children}</Box>\n </Box>\n </Box>\n);\nTableFilterSection.displayName = 'TableFilter.Section';\n\nfunction TableFilterCheckboxField<TValue extends string = string>({\n label,\n options,\n selected,\n onToggle,\n testId,\n}: TableFilterCheckboxFieldProps<TValue>): React.JSX.Element {\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }} data-testid={testId}>\n <Typography sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>{label}</Typography>\n <Box sx={{ display: 'flex', flexDirection: 'column' }}>\n {options.map((option) => {\n const checked = selected.has(option.value);\n return (\n <FormControlLabel\n key={option.value}\n control={\n <Checkbox\n size=\"small\"\n checked={checked}\n onChange={(event) => onToggle(option.value, event.target.checked)}\n data-testid={testId ? `${testId}-${option.value}` : undefined}\n sx={{ py: 0.25 }}\n />\n }\n label={\n <Box component=\"span\" sx={{ fontSize: '0.875rem' }}>\n {option.label}\n {option.count != null && (\n <Box component=\"span\" sx={{ color: 'text.secondary' }}>\n {' '}\n ({option.count})\n </Box>\n )}\n </Box>\n }\n sx={{ ml: -0.5, mr: 0 }}\n />\n );\n })}\n </Box>\n </Box>\n );\n}\nTableFilterCheckboxField.displayName = 'TableFilter.CheckboxField';\n\nfunction parseBound(text: string): number | undefined {\n if (text.trim() === '') return undefined;\n const parsed = Number(text);\n return Number.isNaN(parsed) ? undefined : parsed;\n}\n\n/** One numeric bound input (min or max) for {@link TableFilterRangeField}. */\nfunction RangeBound({\n bound,\n error,\n placeholder,\n step,\n ariaLabel,\n testId,\n onChange,\n}: {\n bound: number | undefined;\n error: boolean;\n placeholder: string;\n step?: number;\n ariaLabel: string;\n testId?: string;\n onChange: (next: number | undefined) => void;\n}): React.JSX.Element {\n return (\n <TextField\n size=\"small\"\n type=\"number\"\n error={error}\n placeholder={placeholder}\n value={bound != null ? String(bound) : ''}\n onChange={(event) => onChange(parseBound(event.target.value))}\n inputProps={{ step, 'aria-label': ariaLabel, 'data-testid': testId }}\n />\n );\n}\n\n/** Inverted range: both ends set and max < min (surfaced to the user as an error). */\nconst isRangeInverted = (value: { min?: number; max?: number }): boolean =>\n value.min != null && value.max != null && value.max < value.min;\n\nconst TableFilterRangeField = ({\n label,\n value,\n onChange,\n unit,\n step,\n minPlaceholder = 'min',\n maxPlaceholder = 'max',\n invalidLabel = 'O máximo deve ser maior ou igual ao mínimo.',\n testId,\n}: TableFilterRangeFieldProps): React.JSX.Element => {\n const invalid = isRangeInverted(value);\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }} data-testid={testId}>\n <Typography sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>\n {label}\n {unit ? ` (${unit})` : ''}\n </Typography>\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>\n <RangeBound\n bound={value.min}\n error={invalid}\n placeholder={minPlaceholder}\n step={step}\n ariaLabel={`${label} ${minPlaceholder}`}\n testId={testId ? `${testId}-min` : undefined}\n onChange={(min) => onChange({ ...value, min })}\n />\n <Typography component=\"span\" sx={{ color: 'text.secondary' }}>\n –\n </Typography>\n <RangeBound\n bound={value.max}\n error={invalid}\n placeholder={maxPlaceholder}\n step={step}\n ariaLabel={`${label} ${maxPlaceholder}`}\n testId={testId ? `${testId}-max` : undefined}\n onChange={(max) => onChange({ ...value, max })}\n />\n </Box>\n {invalid && (\n <Typography\n role=\"alert\"\n data-testid={testId ? `${testId}-error` : undefined}\n sx={{ fontSize: '0.7rem', color: 'error.main' }}\n >\n {invalidLabel}\n </Typography>\n )}\n </Box>\n );\n};\nTableFilterRangeField.displayName = 'TableFilter.RangeField';\n\nTableFilter.Layout = TableFilterLayout;\nTableFilter.Main = TableFilterMain;\nTableFilter.Panel = TableFilterPanel;\nTableFilter.Keyword = TableFilterKeyword;\nTableFilter.Section = TableFilterSection;\nTableFilter.CheckboxField = TableFilterCheckboxField;\nTableFilter.RangeField = TableFilterRangeField;\n","'use client';\n\nimport { createContext, useContext } from 'react';\n\n/** Open/close + active state shared by every `TableFilter` compound part. */\nexport interface TableFilterContextValue {\n /** Whether the filter panel is expanded. */\n open: boolean;\n /** Toggle the panel open/closed. */\n onOpenChange: (open: boolean) => void;\n /** When true, the trigger shows a filled indicator dot. */\n hasActiveFilters: boolean;\n}\n\n/** Backing context. `null` outside a `<TableFilter>` root. */\nexport const TableFilterContext = createContext<TableFilterContextValue | null>(null);\n\n/**\n * Reads the nearest {@link TableFilterContext}.\n *\n * @throws If used outside `<TableFilter>`.\n */\nexport function useTableFilterContext(): TableFilterContextValue {\n const context = useContext(TableFilterContext);\n if (!context) {\n throw new Error('TableFilter compound components must be rendered inside <TableFilter>');\n }\n return context;\n}\n"],"mappings":";AAEA,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,QAAQ,gBAAgB;;;ACbxC,SAAS,eAAe,kBAAkB;AAanC,IAAM,qBAAqB,cAA8C,IAAI;AAO7E,SAAS,wBAAiD;AAC/D,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;;;AD8BI,cA4EI,YA5EJ;AA7BJ,IAAM,cAAc;AAsBb,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AACrB,GAAwC;AACtC,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,MAAM,cAAc,iBAAiB,GACxE,UACH;AAEJ;AACA,YAAY,cAAc;AAE1B,IAAM,oBAAoB,CAAC,EAAE,UAAU,UAAU,MAAiD;AAChG,QAAM,EAAE,KAAK,IAAI,sBAAsB;AACvC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAA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;AAAA,UACnC,UAAU,CAAC,QAAQ,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC;AAAA;AAAA,MAC/C;AAAA,OACF;AAAA,IACC,WACC;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,eAAa,SAAS,GAAG,MAAM,WAAW;AAAA,QAC1C,IAAI,EAAE,UAAU,UAAU,OAAO,aAAa;AAAA,QAE7C;AAAA;AAAA,IACH;AAAA,KAEJ;AAEJ;AACA,sBAAsB,cAAc;AAEpC,YAAY,SAAS;AACrB,YAAY,OAAO;AACnB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,gBAAgB;AAC5B,YAAY,aAAa;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/components/layout/TableFilter/TableFilter.tsx","../src/components/layout/TableFilter/TableFilterContext.tsx"],"sourcesContent":["'use client';\n\nimport CloseIcon from '@mui/icons-material/Close';\nimport SearchIcon from '@mui/icons-material/Search';\nimport {\n Box,\n Checkbox,\n Divider,\n FormControlLabel,\n IconButton,\n InputAdornment,\n Link,\n TextField,\n Typography,\n} from '@mui/material';\nimport React, { useRef, useState } from 'react';\n\nimport { TableFilterContext, useTableFilterContext } from './TableFilterContext';\nimport type {\n TableFilterCheckboxFieldProps,\n TableFilterKeywordProps,\n TableFilterLayoutProps,\n TableFilterMainProps,\n TableFilterPanelProps,\n TableFilterProps,\n TableFilterRangeFieldProps,\n TableFilterSectionProps,\n} from './TableFilter.types';\n\nconst PANEL_WIDTH = 280;\n\n/**\n * Compound filter-panel system, MUI port of the reference `TableFilter`. Provides\n * open/close state; `Panel` slides in from the right beside `Main` (no overlap).\n *\n * @example\n * ```tsx\n * <TableFilter open={open} onOpenChange={setOpen} hasActiveFilters={n > 0}>\n * <TableFilter.Layout>\n * <TableFilter.Main>{table}</TableFilter.Main>\n * <TableFilter.Panel onClearAll={clearAll}>\n * <TableFilter.Keyword value={q} onChange={setQ} />\n * <TableFilter.Section title=\"Attributes\">\n * <TableFilter.CheckboxField label=\"Category\" options={cats} selected={sel} onToggle={toggle} />\n * <TableFilter.RangeField label=\"Price\" unit=\"R$\" value={price} onChange={setPrice} />\n * </TableFilter.Section>\n * </TableFilter.Panel>\n * </TableFilter.Layout>\n * </TableFilter>\n * ```\n */\nexport function TableFilter({\n children,\n open,\n onOpenChange,\n hasActiveFilters = false,\n}: TableFilterProps): React.JSX.Element {\n return (\n <TableFilterContext.Provider value={{ open, onOpenChange, hasActiveFilters }}>\n {children}\n </TableFilterContext.Provider>\n );\n}\nTableFilter.displayName = 'TableFilter';\n\nconst TableFilterLayout = ({ children, className }: TableFilterLayoutProps): React.JSX.Element => {\n const { open } = useTableFilterContext();\n return (\n <Box\n className={className}\n sx={{\n display: 'flex',\n minHeight: 0,\n minWidth: 0,\n flex: 1,\n alignItems: 'stretch',\n overflow: 'hidden',\n gap: open ? 2 : 0,\n }}\n >\n {children}\n </Box>\n );\n};\nTableFilterLayout.displayName = 'TableFilter.Layout';\n\nconst TableFilterMain = ({ children, className }: TableFilterMainProps): React.JSX.Element => (\n <Box className={className} sx={{ minWidth: 0, flex: 1, overflowY: 'auto', overflowX: 'hidden' }}>\n {children}\n </Box>\n);\nTableFilterMain.displayName = 'TableFilter.Main';\n\nconst TableFilterPanel = ({\n children,\n onClearAll,\n ariaLabel = 'Filters',\n clearTestId,\n}: TableFilterPanelProps): React.JSX.Element => {\n const { open } = useTableFilterContext();\n return (\n <Box\n component=\"aside\"\n aria-label={ariaLabel}\n aria-hidden={!open}\n sx={{\n display: 'flex',\n minHeight: 0,\n flexShrink: 0,\n flexDirection: 'column',\n alignSelf: 'stretch',\n overflow: 'hidden',\n bgcolor: 'background.paper',\n width: open ? PANEL_WIDTH : 0,\n borderLeft: open ? 1 : 0,\n borderColor: 'divider',\n transition: 'width 300ms ease-in-out',\n '@media (prefers-reduced-motion: reduce)': { transition: 'none' },\n }}\n >\n <Box\n sx={{\n display: 'flex',\n minHeight: 0,\n flex: 1,\n flexDirection: 'column',\n overflowY: 'auto',\n overflowX: 'hidden',\n visibility: open ? 'visible' : 'hidden',\n opacity: open ? 1 : 0,\n pointerEvents: open ? 'auto' : 'none',\n transition: 'opacity 200ms ease-out',\n }}\n >\n <Box sx={{ boxSizing: 'border-box', display: 'flex', width: '100%', minWidth: 0, flexDirection: 'column', gap: 2.5, p: 2 }}>\n <Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>\n <Link\n component=\"button\"\n type=\"button\"\n underline=\"hover\"\n data-testid={clearTestId}\n onClick={onClearAll}\n sx={{ fontSize: '0.75rem', color: 'text.secondary' }}\n >\n Clear All Filters\n </Link>\n </Box>\n {children}\n </Box>\n </Box>\n </Box>\n );\n};\nTableFilterPanel.displayName = 'TableFilter.Panel';\n\nconst TableFilterKeyword = ({\n value,\n onChange,\n placeholder = 'Press Enter to filter',\n label = 'Filter by keyword',\n testId,\n}: TableFilterKeywordProps): React.JSX.Element => {\n const [draft, setDraft] = useState(value);\n const prevValue = useRef(value);\n if (prevValue.current !== value) {\n prevValue.current = value;\n if (draft !== value) setDraft(value);\n }\n\n const commit = (): void => {\n if (draft !== value) onChange(draft);\n };\n const clearKeyword = (): void => {\n setDraft('');\n if (value !== '') onChange('');\n };\n\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <Typography component=\"label\" sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>\n {label}\n </Typography>\n <TextField\n size=\"small\"\n name=\"keyword\"\n placeholder={placeholder}\n value={draft}\n onChange={(event) => setDraft(event.target.value)}\n onBlur={commit}\n onKeyDown={(event) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n commit();\n }}\n inputProps={{ 'aria-label': label, 'data-testid': testId }}\n InputProps={{\n startAdornment: (\n <InputAdornment position=\"start\">\n <SearchIcon sx={{ fontSize: 16, color: 'text.secondary' }} />\n </InputAdornment>\n ),\n endAdornment:\n draft !== '' ? (\n <InputAdornment position=\"end\">\n <IconButton\n size=\"small\"\n aria-label=\"Clear keyword filter\"\n data-testid={testId ? `${testId}-clear` : undefined}\n onMouseDown={(event) => event.preventDefault()}\n onClick={clearKeyword}\n >\n <CloseIcon sx={{ fontSize: 16 }} />\n </IconButton>\n </InputAdornment>\n ) : null,\n }}\n />\n </Box>\n );\n};\nTableFilterKeyword.displayName = 'TableFilter.Keyword';\n\nconst TableFilterSection = ({ title, children }: TableFilterSectionProps): React.JSX.Element => (\n <Box>\n <Divider sx={{ mb: 2.5 }} />\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>\n <Typography component=\"h2\" sx={{ fontSize: '0.875rem', fontWeight: 600, color: 'text.primary' }}>\n {title}\n </Typography>\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>{children}</Box>\n </Box>\n </Box>\n);\nTableFilterSection.displayName = 'TableFilter.Section';\n\nfunction TableFilterCheckboxField<TValue extends string = string>({\n label,\n options,\n selected,\n onToggle,\n testId,\n}: TableFilterCheckboxFieldProps<TValue>): React.JSX.Element {\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }} data-testid={testId}>\n <Typography sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>{label}</Typography>\n <Box sx={{ display: 'flex', flexDirection: 'column' }}>\n {options.map((option) => {\n const checked = selected.has(option.value);\n return (\n <FormControlLabel\n key={option.value}\n control={\n <Checkbox\n size=\"small\"\n checked={checked}\n onChange={(event) => onToggle(option.value, event.target.checked)}\n data-testid={testId ? `${testId}-${option.value}` : undefined}\n sx={{ py: 0.25 }}\n />\n }\n label={\n <Box component=\"span\" sx={{ fontSize: '0.875rem' }}>\n {option.label}\n {option.count != null && (\n <Box component=\"span\" sx={{ color: 'text.secondary' }}>\n {' '}\n ({option.count})\n </Box>\n )}\n </Box>\n }\n sx={{ ml: -0.5, mr: 0 }}\n />\n );\n })}\n </Box>\n </Box>\n );\n}\nTableFilterCheckboxField.displayName = 'TableFilter.CheckboxField';\n\nfunction parseBound(text: string): number | undefined {\n if (text.trim() === '') return undefined;\n const parsed = Number(text);\n return Number.isNaN(parsed) ? undefined : parsed;\n}\n\n/** One numeric bound input (min or max) for {@link TableFilterRangeField}. */\nfunction RangeBound({\n bound,\n error,\n placeholder,\n step,\n ariaLabel,\n testId,\n onChange,\n}: {\n bound: number | undefined;\n error: boolean;\n placeholder: string;\n step?: number;\n ariaLabel: string;\n testId?: string;\n onChange: (next: number | undefined) => void;\n}): React.JSX.Element {\n return (\n <TextField\n size=\"small\"\n type=\"number\"\n error={error}\n placeholder={placeholder}\n value={bound != null ? String(bound) : ''}\n onChange={(event) => onChange(parseBound(event.target.value))}\n inputProps={{ step, 'aria-label': ariaLabel, 'data-testid': testId }}\n />\n );\n}\n\n/** Inverted range: both ends set and max < min (surfaced to the user as an error). */\nconst isRangeInverted = (value: { min?: number; max?: number }): boolean =>\n value.min != null && value.max != null && value.max < value.min;\n\nconst TableFilterRangeField = ({\n label,\n value,\n onChange,\n unit,\n step,\n minPlaceholder = 'min',\n maxPlaceholder = 'max',\n invalidLabel,\n testId,\n}: TableFilterRangeFieldProps): React.JSX.Element => {\n const invalid = isRangeInverted(value);\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }} data-testid={testId}>\n <Typography sx={{ fontSize: '0.75rem', fontWeight: 500, color: 'text.secondary' }}>\n {label}\n {unit ? ` (${unit})` : ''}\n </Typography>\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>\n <RangeBound\n bound={value.min}\n error={invalid}\n placeholder={minPlaceholder}\n step={step}\n ariaLabel={`${label} ${minPlaceholder}`}\n testId={testId ? `${testId}-min` : undefined}\n onChange={(min) => onChange({ ...value, min })}\n />\n <Typography component=\"span\" sx={{ color: 'text.secondary' }}>\n –\n </Typography>\n <RangeBound\n bound={value.max}\n error={invalid}\n placeholder={maxPlaceholder}\n step={step}\n ariaLabel={`${label} ${maxPlaceholder}`}\n testId={testId ? `${testId}-max` : undefined}\n onChange={(max) => onChange({ ...value, max })}\n />\n </Box>\n {invalid && (\n <Typography\n role=\"alert\"\n data-testid={testId ? `${testId}-error` : undefined}\n sx={{ fontSize: '0.7rem', color: 'error.main' }}\n >\n {invalidLabel}\n </Typography>\n )}\n </Box>\n );\n};\nTableFilterRangeField.displayName = 'TableFilter.RangeField';\n\nTableFilter.Layout = TableFilterLayout;\nTableFilter.Main = TableFilterMain;\nTableFilter.Panel = TableFilterPanel;\nTableFilter.Keyword = TableFilterKeyword;\nTableFilter.Section = TableFilterSection;\nTableFilter.CheckboxField = TableFilterCheckboxField;\nTableFilter.RangeField = TableFilterRangeField;\n","'use client';\n\nimport { createContext, useContext } from 'react';\n\n/** Open/close + active state shared by every `TableFilter` compound part. */\nexport interface TableFilterContextValue {\n /** Whether the filter panel is expanded. */\n open: boolean;\n /** Toggle the panel open/closed. */\n onOpenChange: (open: boolean) => void;\n /** When true, the trigger shows a filled indicator dot. */\n hasActiveFilters: boolean;\n}\n\n/** Backing context. `null` outside a `<TableFilter>` root. */\nexport const TableFilterContext = createContext<TableFilterContextValue | null>(null);\n\n/**\n * Reads the nearest {@link TableFilterContext}.\n *\n * @throws If used outside `<TableFilter>`.\n */\nexport function useTableFilterContext(): TableFilterContextValue {\n const context = useContext(TableFilterContext);\n if (!context) {\n throw new Error('TableFilter compound components must be rendered inside <TableFilter>');\n }\n return context;\n}\n"],"mappings":";AAEA,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,QAAQ,gBAAgB;;;ACbxC,SAAS,eAAe,kBAAkB;AAanC,IAAM,qBAAqB,cAA8C,IAAI;AAO7E,SAAS,wBAAiD;AAC/D,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;;;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rC,QAAQ,SAAS,GAAG,MAAM,SAAS;AAAA,UACnC,UAAU,CAAC,QAAQ,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC;AAAA;AAAA,MAC/C;AAAA,MACA,oBAAC,cAAW,WAAU,QAAO,IAAI,EAAE,OAAO,iBAAiB,GAAG,oBAE9D;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO,MAAM;AAAA,UACb,OAAO;AAAA,UACP,aAAa;AAAA,UACb;AAAA,UACA,WAAW,GAAG,KAAK,IAAI,cAAc;AAAA,UACrC,QAAQ,SAAS,GAAG,MAAM,SAAS;AAAA,UACnC,UAAU,CAAC,QAAQ,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC;AAAA;AAAA,MAC/C;AAAA,OACF;AAAA,IACC,WACC;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,eAAa,SAAS,GAAG,MAAM,WAAW;AAAA,QAC1C,IAAI,EAAE,UAAU,UAAU,OAAO,aAAa;AAAA,QAE7C;AAAA;AAAA,IACH;AAAA,KAEJ;AAEJ;AACA,sBAAsB,cAAc;AAEpC,YAAY,SAAS;AACrB,YAAY,OAAO;AACnB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,gBAAgB;AAC5B,YAAY,aAAa;","names":[]}
|
|
@@ -7,12 +7,11 @@ import {
|
|
|
7
7
|
|
|
8
8
|
// src/components/feedback/ConfirmAction/ConfirmAction.hooks.ts
|
|
9
9
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
10
|
-
var DEFAULT_ERROR_TEXT = "N\xE3o foi poss\xEDvel concluir a a\xE7\xE3o. Tente novamente.";
|
|
11
10
|
function failureMessage(cause, errorText) {
|
|
12
11
|
if (cause instanceof Error && cause.message) return cause.message;
|
|
13
12
|
return errorText;
|
|
14
13
|
}
|
|
15
|
-
function useConfirmAction(onConfirm, errorText
|
|
14
|
+
function useConfirmAction(onConfirm, errorText) {
|
|
16
15
|
const [open, setOpen] = useState(false);
|
|
17
16
|
const [pending, setPending] = useState(false);
|
|
18
17
|
const [error, setError] = useState(null);
|
|
@@ -59,10 +58,9 @@ function useConfirmAction(onConfirm, errorText = DEFAULT_ERROR_TEXT) {
|
|
|
59
58
|
import { Alert, Stack, TextField, Typography } from "@mui/material";
|
|
60
59
|
import React from "react";
|
|
61
60
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
62
|
-
var DEFAULT_CANCEL_TEXT = "Cancelar";
|
|
63
61
|
var DEFAULT_TEST_ID = "confirm-action";
|
|
64
|
-
function confirmBody(description, entityName) {
|
|
65
|
-
if (!entityName) return description ??
|
|
62
|
+
function confirmBody(description, copy, entityName) {
|
|
63
|
+
if (!entityName) return description ?? copy.irreversible;
|
|
66
64
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
67
65
|
/* @__PURE__ */ jsx(Typography, { component: "span", sx: { fontWeight: 600, display: "block" }, children: entityName }),
|
|
68
66
|
description
|
|
@@ -103,12 +101,13 @@ function ConfirmActionDialog({
|
|
|
103
101
|
description,
|
|
104
102
|
entityName,
|
|
105
103
|
confirmText,
|
|
106
|
-
cancelText
|
|
104
|
+
cancelText,
|
|
107
105
|
typeToConfirm,
|
|
108
106
|
typeToConfirmLabel,
|
|
109
107
|
tone = "destructive",
|
|
110
108
|
initialFocus,
|
|
111
|
-
dataTestId = DEFAULT_TEST_ID
|
|
109
|
+
dataTestId = DEFAULT_TEST_ID,
|
|
110
|
+
copy
|
|
112
111
|
}) {
|
|
113
112
|
const [typed, setTyped] = React.useState("");
|
|
114
113
|
React.useEffect(() => {
|
|
@@ -121,7 +120,7 @@ function ConfirmActionDialog({
|
|
|
121
120
|
open: state.open,
|
|
122
121
|
variant: tone === "destructive" ? "destructive" : "default",
|
|
123
122
|
title,
|
|
124
|
-
description: confirmBody(description, entityName),
|
|
123
|
+
description: confirmBody(description, copy, entityName),
|
|
125
124
|
confirmText,
|
|
126
125
|
cancelText,
|
|
127
126
|
loading: state.pending,
|
|
@@ -183,13 +182,13 @@ function withConfirmation(Wrapped, defaults) {
|
|
|
183
182
|
function WithConfirmation(props) {
|
|
184
183
|
const { confirm, onClick } = props;
|
|
185
184
|
const options = resolveOptions(defaults, confirm);
|
|
186
|
-
const state = useConfirmAction(useGuardedHandler(onClick),
|
|
185
|
+
const state = useConfirmAction(useGuardedHandler(onClick), defaults.errorText);
|
|
187
186
|
const { confirm: _confirm, ...rest } = props;
|
|
188
187
|
const forwarded = rest;
|
|
189
188
|
if (!options) return /* @__PURE__ */ jsx3(Wrapped, { ...forwarded });
|
|
190
189
|
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
191
190
|
/* @__PURE__ */ jsx3(Wrapped, { ...forwarded, onClick: state.request }),
|
|
192
|
-
/* @__PURE__ */ jsx3(ConfirmActionDialog, { state, ...options })
|
|
191
|
+
/* @__PURE__ */ jsx3(ConfirmActionDialog, { state, ...options, copy: defaults.copy })
|
|
193
192
|
] });
|
|
194
193
|
}
|
|
195
194
|
WithConfirmation.displayName = `withConfirmation(${Wrapped.displayName ?? Wrapped.name ?? "Component"})`;
|
|
@@ -197,17 +196,20 @@ function withConfirmation(Wrapped, defaults) {
|
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
// src/components/feedback/ConfirmAction/ConfirmButton.tsx
|
|
200
|
-
|
|
201
|
-
Button,
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
function createConfirmButton(copy, errorText) {
|
|
200
|
+
return withConfirmation(Button, {
|
|
201
|
+
cancelText: copy.cancel,
|
|
202
|
+
tone: "destructive",
|
|
203
|
+
errorText,
|
|
204
|
+
copy
|
|
205
|
+
});
|
|
206
|
+
}
|
|
204
207
|
|
|
205
208
|
export {
|
|
206
|
-
DEFAULT_ERROR_TEXT,
|
|
207
209
|
useConfirmAction,
|
|
208
210
|
ConfirmActionDialog,
|
|
209
211
|
ConfirmAction,
|
|
210
212
|
withConfirmation,
|
|
211
|
-
|
|
213
|
+
createConfirmButton
|
|
212
214
|
};
|
|
213
|
-
//# sourceMappingURL=chunk-
|
|
215
|
+
//# sourceMappingURL=chunk-MXPXKORR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/feedback/ConfirmAction/ConfirmAction.hooks.ts","../src/components/feedback/ConfirmAction/ConfirmAction.parts.tsx","../src/components/feedback/ConfirmAction/ConfirmAction.tsx","../src/components/feedback/ConfirmAction/with-confirmation.tsx","../src/components/feedback/ConfirmAction/ConfirmButton.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { ConfirmHandler, UseConfirmActionResult } from './ConfirmAction.types';\n\n/** Used when the guarded action rejects and the caller supplied no wording. */\n\n\n/**\n * What the popup says after a failed attempt.\n *\n * A rejection carrying a message wins: the server's sentence (\"esta categoria\n * ainda tem produtos vinculados\") is the one the operator can act on, and it is\n * strictly better than the generic fallback. Handlers that have nothing useful\n * to say reject with nothing and get `errorText`.\n */\nfunction failureMessage(cause: unknown, errorText: string): string {\n if (cause instanceof Error && cause.message) return cause.message;\n return errorText;\n}\n\n/**\n * The confirmation state machine, headless.\n *\n * It is the whole safety contract in one place, so every consumer gets the same\n * behaviour: the action runs ONLY from `confirm`, never from opening the popup;\n * a second confirm while the first is in flight is dropped (a double-click\n * cannot send two deletes); a rejection keeps the popup open carrying the\n * failure instead of closing over a write that never happened.\n */\nexport function useConfirmAction(\n onConfirm: ConfirmHandler,\n errorText: string,\n): UseConfirmActionResult {\n const [open, setOpen] = useState(false);\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n // `pending` is mirrored in a ref because the two guards that matter — drop a\n // second confirm, ignore a cancel mid-flight — are read inside callbacks that\n // must not be rebuilt on every state change. Reading the state variable there\n // would leave a stale closure holding `false` for the whole in-flight window,\n // which is exactly the double-submit this component exists to prevent.\n const busy = useRef(false);\n\n // The action can settle after the trigger has unmounted (a row deleted from\n // under its own menu), so the settle path must not touch state by then.\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const request = useCallback((): void => {\n setError(null);\n setOpen(true);\n }, []);\n\n const cancel = useCallback((): void => {\n // Inert mid-flight: the write has already left, and closing here would hide\n // its outcome.\n if (busy.current) return;\n setOpen(false);\n setError(null);\n }, []);\n\n const settle = useCallback((failure: string | null): void => {\n busy.current = false;\n if (!mounted.current) return;\n setPending(false);\n setError(failure);\n if (!failure) setOpen(false);\n }, []);\n\n const confirm = useCallback((): void => {\n if (busy.current) return;\n busy.current = true;\n setPending(true);\n setError(null);\n // The handler is invoked synchronously, exactly as a plain `onClick` would\n // be — only the OUTCOME is awaited. The try/catch is what puts a handler\n // that throws synchronously on the same failure path as one that returns a\n // rejected promise.\n try {\n const result = onConfirm();\n void Promise.resolve(result)\n .then(() => settle(null))\n .catch((cause: unknown) => settle(failureMessage(cause, errorText)));\n } catch (cause) {\n settle(failureMessage(cause, errorText));\n }\n }, [errorText, onConfirm, settle]);\n\n return { open, pending, error, request, cancel, confirm };\n}\n","import type { ConfirmActionCopy } from \"../../../copy\";\nimport { Alert, Stack, TextField, Typography } from '@mui/material';\nimport React, { type ReactNode } from 'react';\n\nimport { AlertDialog } from '../../data-display/AlertDialog';\n\nimport type {\n ConfirmInitialFocus,\n ConfirmOptions,\n ConfirmTone,\n UseConfirmActionResult,\n} from './ConfirmAction.types';\n\nconst DEFAULT_TEST_ID = 'confirm-action';\n\n/**\n * The popup's body: the row being acted on, then what happens to it.\n *\n * The NAME is rendered in its own right rather than woven into the sentence, so\n * it is there whatever the caller wrote — \"the popup names the specific entity\"\n * is the one thing that must not depend on each call site remembering to\n * mention it. A body with neither a name nor a description would leave the\n * operator with only the title to decide on, so a neutral fallback covers that.\n */\nfunction confirmBody(\n description: ReactNode,\n copy: ConfirmActionCopy,\n entityName?: string,\n): ReactNode {\n if (!entityName) return description ?? copy.irreversible;\n return (\n <>\n <Typography component=\"span\" sx={{ fontWeight: 600, display: \"block\" }}>\n {entityName}\n </Typography>\n {description}\n </>\n );\n}\n\n/** Destructive dialogs open on Cancel; anything else opens on the confirm. */\nfunction resolveInitialFocus(\n tone: ConfirmTone,\n initialFocus?: ConfirmInitialFocus,\n): ConfirmInitialFocus {\n if (initialFocus) return initialFocus;\n return tone === 'destructive' ? 'cancel' : 'confirm';\n}\n\n/**\n * The type-to-confirm field. Rendered only when `typeToConfirm` is set, which\n * should be rare: it is the guard for actions with NO recovery path, where a\n * click is too cheap a gesture. Comparison is exact — trimmed of surrounding\n * whitespace only, so a trailing space from a paste does not read as a mismatch.\n */\nfunction TypeToConfirmField({\n expected,\n label,\n value,\n onChange,\n disabled,\n dataTestId,\n}: {\n expected: string;\n label?: string;\n value: string;\n onChange: (next: string) => void;\n disabled: boolean;\n dataTestId: string;\n}): React.ReactElement {\n return (\n <Stack spacing={1} sx={{ mt: 2 }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {label ?? `Digite \"${expected}\" para confirmar.`}\n </Typography>\n <TextField\n size=\"small\"\n value={value}\n disabled={disabled}\n onChange={(event) => onChange(event.target.value)}\n // On the INPUT rather than the wrapper: a test id on MUI's TextField\n // lands on the outer div, which is not the node a test can type into.\n inputProps={{\n 'aria-label': label ?? `Digite ${expected} para confirmar`,\n 'data-testid': `${dataTestId}-type-to-confirm`,\n }}\n />\n </Stack>\n );\n}\n\nexport interface ConfirmActionDialogProps extends ConfirmOptions {\n /** The fallback body when no entity is named. REQUIRED — no default copy. */\n copy: ConfirmActionCopy;\n state: UseConfirmActionResult;\n}\n\n/**\n * The popup itself: an `AlertDialog` in its destructive skin, plus the two\n * things a bare AlertDialog has no opinion about — the failure the last attempt\n * produced (shown IN the dialog, which stays open, rather than closing over a\n * write that never landed) and the optional type-to-confirm gate.\n */\nexport function ConfirmActionDialog({\n state,\n title,\n description,\n entityName,\n confirmText,\n cancelText,\n typeToConfirm,\n typeToConfirmLabel,\n tone = 'destructive',\n initialFocus,\n dataTestId = DEFAULT_TEST_ID,\n copy,\n}: ConfirmActionDialogProps): React.ReactElement {\n const [typed, setTyped] = React.useState('');\n\n // Every fresh open starts from an empty field: carrying the previous answer\n // over would hand the next delete a pre-satisfied gate.\n React.useEffect(() => {\n if (state.open) setTyped('');\n }, [state.open]);\n\n const gateUnmet = typeToConfirm !== undefined && typed.trim() !== typeToConfirm;\n\n return (\n <AlertDialog\n open={state.open}\n variant={tone === 'destructive' ? 'destructive' : 'default'}\n title={title}\n description={confirmBody(description, copy, entityName)}\n confirmText={confirmText}\n cancelText={cancelText}\n loading={state.pending}\n confirmDisabled={gateUnmet}\n initialFocus={resolveInitialFocus(tone, initialFocus)}\n onConfirm={state.confirm}\n onCancel={state.cancel}\n onClose={state.cancel}\n data-testid={dataTestId}\n >\n {state.error && (\n <Alert severity=\"error\" sx={{ mt: 1 }} data-testid={`${dataTestId}-error`}>\n {state.error}\n </Alert>\n )}\n {typeToConfirm !== undefined && (\n <TypeToConfirmField\n expected={typeToConfirm}\n label={typeToConfirmLabel}\n value={typed}\n onChange={setTyped}\n disabled={state.pending}\n dataTestId={dataTestId}\n />\n )}\n </AlertDialog>\n );\n}\n","import React from 'react';\n\nimport { useConfirmAction } from './ConfirmAction.hooks';\nimport { ConfirmActionDialog } from './ConfirmAction.parts';\nimport type { ConfirmActionProps } from './ConfirmAction.types';\n\n/**\n * Wraps any trigger in a confirmation popup.\n *\n * The trigger is a render prop rather than a fixed element, so the same guard\n * covers a button, a dropdown item, an icon or a table row action without this\n * component knowing what any of them look like. The guarded handler runs ONLY\n * after the operator confirms:\n *\n * ```tsx\n * <ConfirmAction\n * title=\"Excluir a categoria?\"\n * entityName={row.name}\n * description=\"Ela vai para a lixeira e pode ser restaurada de lá.\"\n * confirmText=\"Excluir\"\n * onConfirm={() => deleteCategoryAction({ tenantSlug, id: row.id })}\n * >\n * {(request) => <Button color=\"danger\" onClick={request}>Excluir</Button>}\n * </ConfirmAction>\n * ```\n *\n * For the common case — an existing button whose `onClick` is already the\n * destructive write — reach for {@link withConfirmation} instead, which needs\n * no restructuring of the call site.\n */\nexport function ConfirmAction({\n onConfirm,\n children,\n ...options\n}: ConfirmActionProps): React.ReactElement {\n const state = useConfirmAction(onConfirm, options.errorText);\n\n return (\n <>\n {children(state.request, { pending: state.pending })}\n <ConfirmActionDialog state={state} {...options} />\n </>\n );\n}\n\nConfirmAction.displayName = 'ConfirmAction';\n","import type { ConfirmActionCopy } from '../../../copy';\nimport React from 'react';\nimport type { ComponentType } from 'react';\n\nimport { useConfirmAction } from './ConfirmAction.hooks';\nimport { ConfirmActionDialog } from './ConfirmAction.parts';\nimport type {\n ConfirmHandler,\n ConfirmOptions,\n ConfirmableComponent,\n ConfirmableProps,\n WithConfirmationProps,\n} from './ConfirmAction.types';\n\n/**\n * Merge the HOC's baked-in defaults with the per-instance `confirm` prop.\n * Returns null when the instance opts out (`confirm={false}`) or when neither\n * side supplies the two fields a confirmation cannot be written without — the\n * question and the verb. A null result means \"render the plain component\",\n * which keeps the wrapped export usable in harmless contexts.\n */\nfunction resolveOptions(\n defaults: Partial<ConfirmOptions> | undefined,\n instance: Partial<ConfirmOptions> | false | undefined,\n): ConfirmOptions | null {\n if (instance === false) return null;\n const merged = { ...defaults, ...instance };\n if (!merged.title || !merged.confirmText) return null;\n return { ...merged, title: merged.title, confirmText: merged.confirmText };\n}\n\n/**\n * Adapt the wrapped component's `onClick` into a {@link ConfirmHandler}.\n *\n * The click argument is dropped (see `ConfirmHandler`) and the return value is\n * narrowed: a promise is handed back so the popup can hold its pending state\n * until the write settles, anything else becomes `undefined`. A component with\n * no `onClick` has nothing to guard, so confirming is a no-op.\n */\nfunction useGuardedHandler(onClick: ConfirmableProps['onClick']): ConfirmHandler {\n return React.useCallback((): void | Promise<unknown> => {\n const result = onClick?.();\n return result instanceof Promise ? result : undefined;\n }, [onClick]);\n}\n\n/**\n * Give any click-driven component a confirmation popup, without restructuring\n * the call site.\n *\n * The wrapped component's own `onClick` becomes the GUARDED action: clicking\n * now opens the popup, and the handler runs only if the operator confirms. It\n * inherits the whole contract from `useConfirmAction` — cancel sends nothing, a\n * returned promise holds the popup in its pending state so a double-click\n * cannot fire two writes, and a rejection keeps the popup open carrying the\n * error.\n *\n * ```tsx\n * const ConfirmButton = withConfirmation(Button);\n *\n * <ConfirmButton\n * color=\"danger\"\n * onClick={() => deleteCategoryAction({ tenantSlug, id: row.id })}\n * confirm={{\n * title: \"Excluir a categoria?\",\n * entityName: row.name,\n * description: \"Ela vai para a lixeira e pode ser restaurada de lá.\",\n * confirmText: \"Excluir\",\n * }}\n * >\n * Excluir\n * </ConfirmButton>\n * ```\n *\n * Bake the wording in once when the same guard repeats — `withConfirmation(Button,\n * { confirmText: \"Excluir\" })` — and let each instance override what differs.\n * `confirm={false}` falls through to the plain component.\n *\n * Refs are not forwarded: the HOC renders a fragment (trigger + popup), so there\n * is no single node to hand back. Wrap a component that needs a ref at its own\n * call site with {@link ConfirmAction} instead.\n */\nexport function withConfirmation<P extends ConfirmableProps>(\n Wrapped: ComponentType<P>,\n defaults: Partial<ConfirmOptions> & { errorText: string; copy: ConfirmActionCopy },\n): ConfirmableComponent<P> {\n function WithConfirmation(props: P & WithConfirmationProps): React.ReactElement {\n const { confirm, onClick } = props;\n const options = resolveOptions(defaults, confirm);\n const state = useConfirmAction(useGuardedHandler(onClick), defaults.errorText);\n\n // `confirm` is ours and must not reach the DOM — an unknown attribute on a\n // <button> is a React warning at every render. The cast is the standard HOC\n // one: TypeScript cannot prove `Omit<P & X, 'confirm'>` is still a `P`.\n const { confirm: _confirm, ...rest } = props;\n const forwarded = rest as unknown as P;\n\n if (!options) return <Wrapped {...forwarded} />;\n\n return (\n <>\n <Wrapped {...forwarded} onClick={state.request} />\n <ConfirmActionDialog state={state} {...options} copy={defaults.copy} />\n </>\n );\n }\n\n WithConfirmation.displayName = `withConfirmation(${\n Wrapped.displayName ?? Wrapped.name ?? 'Component'\n })`;\n\n return WithConfirmation;\n}\n","import type { ConfirmActionCopy } from '../../../copy';\nimport { Button } from '../../form/Button';\nimport type { ButtonProps } from '../../form/Button/Button.types';\n\nimport { withConfirmation } from './with-confirmation';\nimport type { ConfirmableComponent } from './ConfirmAction.types';\n\n/**\n * The library `Button`, already wrapped — the shape most call sites want.\n *\n * Adding the guard to an existing button is then an import swap plus the\n * `confirm` prop; the button's own props (colour, size, icon) are untouched.\n * The baked-in defaults are only the wording and tone every destructive\n * confirmation shares, and each instance can still override them.\n */\nexport function createConfirmButton(\n copy: ConfirmActionCopy,\n errorText: string,\n): ConfirmableComponent<ButtonProps> {\n return withConfirmation<ButtonProps>(Button, {\n cancelText: copy.cancel,\n tone: 'destructive',\n errorText,\n copy,\n });\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAezD,SAAS,eAAe,OAAgB,WAA2B;AACjE,MAAI,iBAAiB,SAAS,MAAM,QAAS,QAAO,MAAM;AAC1D,SAAO;AACT;AAWO,SAAS,iBACd,WACA,WACwB;AACxB,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAOtD,QAAM,OAAO,OAAO,KAAK;AAIzB,QAAM,UAAU,OAAO,IAAI;AAC3B,YAAU,MAAM;AACd,YAAQ,UAAU;AAClB,WAAO,MAAM;AACX,cAAQ,UAAU;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,QAAM,UAAU,YAAY,MAAY;AACtC,aAAS,IAAI;AACb,YAAQ,IAAI;AAAA,EACd,GAAG,CAAC,CAAC;AAEL,QAAM,SAAS,YAAY,MAAY;AAGrC,QAAI,KAAK,QAAS;AAClB,YAAQ,KAAK;AACb,aAAS,IAAI;AAAA,EACf,GAAG,CAAC,CAAC;AAEL,QAAM,SAAS,YAAY,CAAC,YAAiC;AAC3D,SAAK,UAAU;AACf,QAAI,CAAC,QAAQ,QAAS;AACtB,eAA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,KAAC,WAAS,GAAG,WAAW,SAAS,MAAM,SAAS;AAAA,MAChD,gBAAAA,KAAC,uBAAoB,OAAe,GAAG,SAAS,MAAM,SAAS,MAAM;AAAA,OACvE;AAAA,EAEJ;AAEA,mBAAiB,cAAc,oBAC7B,QAAQ,eAAe,QAAQ,QAAQ,WACzC;AAEA,SAAO;AACT;;;ACjGO,SAAS,oBACd,MACA,WACmC;AACnC,SAAO,iBAA8B,QAAQ;AAAA,IAC3C,YAAY,KAAK;AAAA,IACjB,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["Fragment","jsx","jsxs","React","Fragment","jsx","jsxs","React"]}
|
|
@@ -11,11 +11,6 @@ import {
|
|
|
11
11
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
12
|
import { cepDigits, formatCep, isValidCep } from "@12-apps/forms-core";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
var STATUS_TEXT = {
|
|
15
|
-
loading: "Buscando endere\xE7o\u2026",
|
|
16
|
-
found: "Endere\xE7o preenchido pelo CEP.",
|
|
17
|
-
notfound: "CEP n\xE3o encontrado \u2014 preencha o endere\xE7o manualmente."
|
|
18
|
-
};
|
|
19
14
|
function useCepLookup({
|
|
20
15
|
digits,
|
|
21
16
|
complete,
|
|
@@ -61,10 +56,11 @@ function useCepLookup({
|
|
|
61
56
|
function CepStatus({
|
|
62
57
|
status,
|
|
63
58
|
testId,
|
|
64
|
-
suppressed
|
|
59
|
+
suppressed,
|
|
60
|
+
copy
|
|
65
61
|
}) {
|
|
66
62
|
const visible = !suppressed && status !== "idle";
|
|
67
|
-
return /* @__PURE__ */ jsx("span", { id: `${testId}-status`, role: "status", "aria-live": "polite", children: visible && /* @__PURE__ */ jsx(FormMessage, { error: status === "notfound", dataTestId: `${testId}-${status}`, children:
|
|
63
|
+
return /* @__PURE__ */ jsx("span", { id: `${testId}-status`, role: "status", "aria-live": "polite", children: visible && /* @__PURE__ */ jsx(FormMessage, { error: status === "notfound", dataTestId: `${testId}-${status}`, children: copy[status] }) });
|
|
68
64
|
}
|
|
69
65
|
function CepField({
|
|
70
66
|
value,
|
|
@@ -78,7 +74,8 @@ function CepField({
|
|
|
78
74
|
disabled = false,
|
|
79
75
|
debounceMs = 500,
|
|
80
76
|
name = "postalCode",
|
|
81
|
-
dataTestId
|
|
77
|
+
dataTestId,
|
|
78
|
+
copy
|
|
82
79
|
}) {
|
|
83
80
|
const testId = dataTestId ?? `cep-field-${name}`;
|
|
84
81
|
const status = useCepLookup({
|
|
@@ -116,11 +113,11 @@ function CepField({
|
|
|
116
113
|
}
|
|
117
114
|
),
|
|
118
115
|
error && /* @__PURE__ */ jsx(FormMessage, { error: true, dataTestId: `${testId}-message`, children: error }),
|
|
119
|
-
/* @__PURE__ */ jsx(CepStatus, { status, testId, suppressed: Boolean(error) })
|
|
116
|
+
/* @__PURE__ */ jsx(CepStatus, { status, testId, suppressed: Boolean(error), copy })
|
|
120
117
|
] });
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
export {
|
|
124
121
|
CepField
|
|
125
122
|
};
|
|
126
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-N554AFDB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/form/CepField/CepField.tsx"],"sourcesContent":["'use client';\n\nimport type { CepFieldCopy } from \"../../../copy\";\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { cepDigits, formatCep, isValidCep } from '@12-apps/forms-core';\n\nimport { FormControl, FormLabel, FormMessage } from '../Form';\nimport { Input } from '../Input';\nimport type { CepAddress, CepFieldProps, CepLookupStatus } from './CepField.types';\n\n/** Everything {@link useCepLookup} needs, so the hook signature stays flat. */\ninterface LookupOptions {\n digits: string;\n complete: boolean;\n disabled: boolean;\n debounceMs: number;\n onLookup?: (cep: string) => Promise<CepAddress | null>;\n onResolved?: (address: CepAddress) => void;\n onNotFound?: () => void;\n}\n\n/**\n * Debounced, race-safe CEP resolution.\n *\n * Two guards earn their keep here: a monotonic sequence id, bumped\n * synchronously on every new query, so a slow response for a since-edited CEP\n * can never land; and a \"last queried\" marker, so re-rendering (or the caller\n * re-masking the same value) never re-hits the provider.\n */\nfunction useCepLookup({\n digits,\n complete,\n disabled,\n debounceMs,\n onLookup,\n onResolved,\n onNotFound,\n}: LookupOptions): CepLookupStatus {\n const [status, setStatus] = useState<CepLookupStatus>('idle');\n const lastQueriedRef = useRef('');\n const seqRef = useRef(0);\n // Latest callbacks, read at call time — keeps them out of the effect deps so\n // an inline arrow from the caller doesn't re-trigger the lookup every render.\n const lookupRef = useRef(onLookup);\n const resolvedRef = useRef(onResolved);\n const notFoundRef = useRef(onNotFound);\n lookupRef.current = onLookup;\n resolvedRef.current = onResolved;\n notFoundRef.current = onNotFound;\n\n useEffect(() => {\n if (!complete || disabled || !lookupRef.current) {\n // Editing away from a complete CEP drops any stale status and forgets the\n // last query, so re-typing the same CEP resolves again.\n seqRef.current += 1;\n setStatus('idle');\n lastQueriedRef.current = '';\n return;\n }\n if (lastQueriedRef.current === digits) return;\n\n const mySeq = (seqRef.current += 1);\n const handle = setTimeout(() => {\n lastQueriedRef.current = digits;\n setStatus('loading');\n void (async () => {\n // A failing lookup is treated exactly like \"not found\" — the user types\n // the address instead. Never surfaced as a crash. Going through\n // `Promise.resolve().then` rather than calling directly covers the two\n // failure modes an `await … .catch()` misses: a lookup that throws\n // SYNCHRONOUSLY, and one that returns something other than a promise.\n const address = await Promise.resolve()\n .then(() => lookupRef.current?.(digits))\n .catch(() => null);\n if (seqRef.current !== mySeq) return;\n setStatus(address ? 'found' : 'notfound');\n // A miss is reported too, so a caller that filled from a PREVIOUS CEP\n // can undo it rather than leaving that address under this CEP.\n if (address) resolvedRef.current?.(address);\n else notFoundRef.current?.();\n })();\n }, debounceMs);\n\n return () => clearTimeout(handle);\n }, [digits, complete, disabled, debounceMs]);\n\n return status;\n}\n\n/**\n * The lookup outcome as a live region, so screen readers announce it without\n * stealing focus. Silent while idle, and while the caller is showing its own\n * validation error (which would otherwise stack two messages).\n */\nfunction CepStatus({\n status,\n testId,\n suppressed,\n copy,\n}: {\n status: CepLookupStatus;\n testId: string;\n suppressed: boolean;\n copy: CepFieldCopy;\n}): React.ReactElement {\n const visible = !suppressed && status !== 'idle';\n return (\n <span id={`${testId}-status`} role=\"status\" aria-live=\"polite\">\n {visible && (\n <FormMessage error={status === 'notfound'} dataTestId={`${testId}-${status}`}>\n {copy[status as Exclude<CepLookupStatus, 'idle'>]}\n </FormMessage>\n )}\n </span>\n );\n}\n\n/**\n * A CEP input that fills the rest of the address in.\n *\n * The pattern every Brazilian form has used for twenty years: type eight\n * digits, and logradouro/bairro/cidade/UF arrive on their own. This is the\n * reusable half — masking, validation, debouncing, race-safety and status —\n * with the actual lookup injected via `onLookup`, so the same component serves\n * a supplier form, a store-location form or a delivery checkout without\n * knowing anything about providers or auth.\n *\n * Resolution is best-effort by design. A provider outage, an unknown CEP or a\n * timeout leaves the field exactly as usable as a plain text input — the user\n * types the address themselves. Autofill never blocks.\n *\n * @example\n * ```tsx\n * <CepField\n * value={cep}\n * onChange={setCep}\n * onLookup={(c) => fetch(`/api/…/lookup/cep/${c}`).then((r) => r.json()).then((b) => b.data)}\n * onResolved={(a) => { setStreet(a.street ?? ''); setCity(a.city ?? ''); }}\n * />\n * ```\n */\nexport function CepField({\n value,\n onChange,\n onLookup,\n onResolved,\n onNotFound,\n label = 'CEP',\n placeholder = '00000-000',\n error,\n disabled = false,\n debounceMs = 500,\n name = 'postalCode',\n dataTestId,\n copy,\n}: CepFieldProps): React.ReactElement {\n const testId = dataTestId ?? `cep-field-${name}`;\n\n const status = useCepLookup({\n digits: cepDigits(value),\n complete: isValidCep(value),\n disabled,\n debounceMs,\n onLookup,\n onResolved,\n onNotFound,\n });\n\n const handleChange = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => onChange(formatCep(event.target.value)),\n [onChange],\n );\n\n return (\n <FormControl fullWidth>\n {label && (\n <FormLabel htmlFor={name} error={Boolean(error)}>\n {label}\n </FormLabel>\n )}\n <Input\n id={name}\n name={name}\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"postal-code\"\n placeholder={placeholder}\n value={value}\n error={Boolean(error)}\n disabled={disabled}\n loading={status === 'loading'}\n onChange={handleChange}\n data-testid={testId}\n aria-describedby={`${testId}-status`}\n aria-busy={status === 'loading'}\n />\n {error && (\n <FormMessage error dataTestId={`${testId}-message`}>\n {error}\n </FormMessage>\n )}\n <CepStatus status={status} testId={testId} suppressed={Boolean(error)} copy={copy} />\n </FormControl>\n );\n}\n\nexport default CepField;\n"],"mappings":";;;;;;;;;;AAGA,SAAgB,aAAa,WAAW,QAAQ,gBAAgB;AAEhE,SAAS,WAAW,WAAW,kBAAkB;AAyGzC,cAiEJ,YAjEI;AAhFR,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmC;AACjC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0B,MAAM;AAC5D,QAAM,iBAAiB,OAAO,EAAE;AAChC,QAAM,SAAS,OAAO,CAAC;AAGvB,QAAM,YAAY,OAAO,QAAQ;AACjC,QAAM,cAAc,OAAO,UAAU;AACrC,QAAM,cAAc,OAAO,UAAU;AACrC,YAAU,UAAU;AACpB,cAAY,UAAU;AACtB,cAAY,UAAU;AAEtB,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,YAAY,CAAC,UAAU,SAAS;AAG/C,aAAO,WAAW;AAClB,gBAAU,MAAM;AAChB,qBAAe,UAAU;AACzB;AAAA,IACF;AACA,QAAI,eAAe,YAAY,OAAQ;AAEvC,UAAM,QAAS,OAAO,WAAW;AACjC,UAAM,SAAS,WAAW,MAAM;AAC9B,qBAAe,UAAU;AACzB,gBAAU,SAAS;AACnB,YAAM,YAAY;AAMhB,cAAM,UAAU,MAAM,QAAQ,QAAQ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AK,GAC3C,iBACH;AAAA,IAEF;AAAA,MAAC;AAAA;AAAA,QACC,IAAI;AAAA,QACJ;AAAA,QACA,MAAK;AAAA,QACL,WAAU;AAAA,QACV,cAAa;AAAA,QACb;AAAA,QACA;AAAA,QACA,OAAO,QAAQ,KAAK;AAAA,QACpB;AAAA,QACA,SAAS,WAAW;AAAA,QACpB,UAAU;AAAA,QACV,eAAa;AAAA,QACb,oBAAkB,GAAG,MAAM;AAAA,QAC3B,aAAW,WAAW;AAAA;AAAA,IACxB;AAAA,IACC,SACC,oBAAC,eAAY,OAAK,MAAC,YAAY,GAAG,MAAM,YACrC,iBACH;AAAA,IAEF,oBAAC,aAAU,QAAgB,QAAgB,YAAY,QAAQ,KAAK,GAAG,MAAY;AAAA,KACrF;AAEJ;","names":[]}
|
|
@@ -1021,24 +1021,6 @@ import ViewIcon from "@mui/icons-material/Visibility";
|
|
|
1021
1021
|
import { Box as Box8, Button as Button7, IconButton as IconButton2, Menu as Menu5, MenuItem as MenuItem5, Popover, Stack, Typography as Typography4 } from "@mui/material";
|
|
1022
1022
|
import { useState as useState5 } from "react";
|
|
1023
1023
|
import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1024
|
-
var DEFAULT_LABELS = {
|
|
1025
|
-
trigger: "Vis\xF5es",
|
|
1026
|
-
mainView: "Vis\xE3o principal",
|
|
1027
|
-
pinned: "Fixadas",
|
|
1028
|
-
recent: "Recentes",
|
|
1029
|
-
empty: "Nenhuma vis\xE3o salva ainda.",
|
|
1030
|
-
saveCurrent: "+ Salvar vis\xE3o atual",
|
|
1031
|
-
manageAll: "Gerenciar vis\xF5es",
|
|
1032
|
-
apply: "Aplicar",
|
|
1033
|
-
setDefault: "Definir como padr\xE3o",
|
|
1034
|
-
pin: "Fixar na barra lateral",
|
|
1035
|
-
unpin: "Desafixar",
|
|
1036
|
-
share: "Compartilhar com a equipe",
|
|
1037
|
-
unshare: "Tornar privada",
|
|
1038
|
-
edit: "Editar",
|
|
1039
|
-
remove: "Excluir",
|
|
1040
|
-
defaultTag: "Padr\xE3o"
|
|
1041
|
-
};
|
|
1042
1024
|
var RECENT_LIMIT = 5;
|
|
1043
1025
|
function DefaultTag({ label, testId }) {
|
|
1044
1026
|
return /* @__PURE__ */ jsx8(
|
|
@@ -1189,7 +1171,7 @@ function SavedViewsMenu({
|
|
|
1189
1171
|
action();
|
|
1190
1172
|
close();
|
|
1191
1173
|
};
|
|
1192
|
-
const labels =
|
|
1174
|
+
const labels = labelOverrides;
|
|
1193
1175
|
const pinned = views.filter((view) => view.pinned);
|
|
1194
1176
|
const recent = views.filter((view) => !view.pinned).slice(0, RECENT_LIMIT);
|
|
1195
1177
|
const handlers = {
|
|
@@ -1260,4 +1242,4 @@ export {
|
|
|
1260
1242
|
ColumnsMenu,
|
|
1261
1243
|
SavedViewsMenu
|
|
1262
1244
|
};
|
|
1263
|
-
//# sourceMappingURL=chunk-
|
|
1245
|
+
//# sourceMappingURL=chunk-R5ZQZSEQ.js.map
|