Version 6.0.0 introduces MosaicContext
offering a centralized control over some of the main library features.
An instance of MosaicContext
must be added up in the component tree in order to let Mosaic components leverage its features. Good starting points can either be index
or App
component:
<MosaicContextProvider ... >
<App />
</MosaicContextProvider>
This is mandatory to use Mosaic localization and responsive flags of single components (e.g. Modal
).
The key features currently available with the MosaicContext
are:
- agnostic localization
- detection of view type (mobile / tablet)
This is the interface of the MosaicContextProvider
:
{
breakpoints?: {
// Breakpoint MUI type: 'sm' | 'md' | 'lg' ...
mobile?: Breakpoint; // Defaults to 'sm'
view?: Breakpoint; // Defaults to 'md'
},
localize: (key: string) => string;
}
If you are approaching migration from 0.x please read the following notes. 1.x introduces some breaking changes and new features, described below:
Export of *Intl
components has been removed in favour of a new approach which simplifies for the final user to have localized components.
Mosaic localizable components now use a dedicated boolean flag called localized
to make all supported strings localized.
For each component, the documentation tells the user if the component can be localized and if so, it lists all the localizable properties under the Intl
section.
The benefits from previous approach are several:
- same export / import for component: remove
Intl
import and just addlocalize
property to standard component - ability to localize n properties of the same component
- ability to localize nested components
- removed misleading
labelId
property - less code to maintain
- door open to future possibility of defining which props to localize and which not...
Below three common use cases of migration for localized components. For other components, use the same pattern, applying the related documentation.
Button
Old code:
import { ButtonIntl } from '@melfore/mosaic';
...
<ButtonIntl
disabled={disabled}
labelId={labelId}
icon={{ name: IconName }}
onClick={() => {}}
/>
New code:
import { Button } from '@melfore/mosaic';
...
<Button
disabled={disabled}
label={labelId}
localized
icon={{ name: IconName }}
onClick={() => {}}
/>
InputNumber
Old code:
import { InputNumberIntl } from '@melfore/mosaic';
<InputNumberIntl
required
labelId={labelId}
minValue={1}
onChange={() => {}}
value={value}
/>
New code:
import { InputNumber } from '@melfore/mosaic';
<InputNumber
required
label={labelId}
localized
minValue={1}
onChange={() => {}}
value={value}
/>
Typography
Old code:
import { TypographyIntl } from '@melfore/mosaic';
...
<TypographyIntl labelId={titleId} variant={TypographyVariants.pagetitle} />
New code:
import { Typography } from '@melfore/mosaic';
...
<Typography localized variant={TypographyVariants.pagetitle}>
{titleId}
</Typography>
Some components have had breaking changes:
-
Text can be passed in as
children
or using thecontent
property:Old code:
<Typography label="Text to display" />
New code:
<Typography> Text to display </Typography>
-
property
bottomSpacing
is now defaulted to false
-
label
property is now mandatory -
onClick
property ofButton
andIconButton
now internally handles click event, so method signature becomes() => void
(previously it was(event: any) => void
)Old code:
<Button onClick={(event: any) => doSomething()} />
New code:
<Button onClick={() => doSomething()} />
-
dropped support for
title
andtitleVariant
properties but ratherheader
andcontent
Old code:
<ListItem title="List Item Text" />
New code:
<ListItem> List Item Text </ListItem>
-
property
dense
is now defaulted tofalse
collapsible
property ofCard
is now aReactNode
(previously it was aReactElement
)- renamed
InputDataType
enum toInputType
- added new
language
icon
While waiting for Storybook 6 to happen (see issue #), some changes were done to the current Documentation, most of which reflects most important code changes.
Quickly:
- Localizable and Testable icons on top of page near component name
- List of all localizable props
- Testing instructions targeting also component subparts (with examples)
We are commitizen friendly!
Meaning that each commit must respect most common commit message guidelines.
Using the script npm run commit
a commit prompt is shown to guide the user in writing the commit message (thanks to git-cz
package).
This kicks-in the semantic-release
package that from next-version-on will take care of versioning, writing release notes and changelogs automagically.