/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react';
import { RenderHTMLProps } from 'react-native-render-html';
import RefCssProcessor from '../components/RefCssProcessor';
import Page from '../Page';
import useToolkit from '../toolkit/useToolkit';
import inlineStylesConfig from './cards/inlineStylesConfig';
const mixedStyleExample = `const tagsStyles = {
body: {
whiteSpace: 'normal',
color: 'gray'
},
a: {
color: 'green'
}
}`;
const mixedStyleRenderCard: RenderHTMLProps = {
source: {
html: `
Hello world!
A link!
`
},
tagsStyles: {
body: {
whiteSpace: 'normal',
color: 'gray'
},
a: {
color: 'green'
}
}
};
export default function PageGuideStylingComponents() {
const {
Acronym,
Admonition,
Bold,
Header,
Paragraph,
Chapter,
DList,
DListItem,
DListTitle,
Section,
SourceDisplay,
RefLibrary,
RefDoc,
RefRNSymbol,
RefHtmlElement,
RefHtmlAttr,
RefCssProperty,
RefRenderHtmlProp,
RefRenderHTMLExport,
RefTRE,
RefCSSProcessor,
RenderHtmlCard,
InlineCode,
Hyperlink,
List,
ListItem,
SvgFigure
} = useToolkit();
return (
You are kindly advised to read {' '}
before continuing.
Inline styles set via the HTML attribute
are processed by the library. You don't need to
wonder if a CSS property will break your app: the CSS processor acts
as a compatibility layer between React Native styles and CSS
properties. This library gives you leverage on inline CSS processing
via multiple props:
Disable inline styles processing altogether.
Whitelist the camel-cased CSS properties that you wish to be
included.
Blacklist the camel-cased CSS properties that you wish to be
excluded.
Let's try it out:
The component has four props
to customize elements styles:
The styles for the root component. Inheritable styles will be
inherited by all children.
Target elements with the HTML attribute.
Target elements with the HTML {' '}
attribute;
Target elements by tag name.
Each of these props is a record mapping identifiers with a{' '}
.
There is not (yet) ways to provide{' '}
CSS selectors
{' '}
to target elements. Because it would require a full-featured CSS
parser to build an AST, this feature might be supported in the future
with an extension.
A mixed style declaration is an object similar to{' '}
's create method argument values. However,
it supports a blend of React Native{' '}
ViewStyle,{' '}
TextStyle and camel-cased{' '}
CSS properties
. See for a complete reference.
In the above snippet, mixed-style declarations are the objects
defined as values of the tagsStyles record.
A few important comments:
Line 2. The will
always be present and can be confidently targeted, event when
missing in the HTML snippet.
Line 3. This is the default property, with the
exception of and a few other tags.
Line 4. Thanks to CSS inheritence, all textual
children of will default to this
property.
Line 7. The implements CSS
specificity. A rule targetting the {' '}
element will override rules defined for its ancestors (in this
case,
).
You should never provide styles from React Native{' '}
. These will not work.
);
}