import {StyleSheet, Text, View} from 'react-native';
/**
* Minimal icons drawn with Views and text glyphs. They are the defaults used
* when a component needs an icon and none was provided, so the library works
* without any icon dependency. Every one of them can be replaced through the
* corresponding `IconProp`.
*/
export type GlyphProps = {
size?: number;
color?: string;
testID?: string;
};
const box = (size: number) => ({
width: size,
height: size,
alignItems: 'center' as const,
justifyContent: 'center' as const,
});
export const CheckGlyph = ({size = 20, color = '#000', testID}: GlyphProps) => (
);
export const CloseGlyph = ({size = 20, color = '#000', testID}: GlyphProps) => {
const bar = {
position: 'absolute' as const,
width: size * 0.8,
height: Math.max(size * 0.12, 1.5),
borderRadius: size,
backgroundColor: color,
};
return (
);
};
export const PlusGlyph = ({size = 20, color = '#000', testID}: GlyphProps) => {
const bar = {
position: 'absolute' as const,
width: size * 0.7,
height: Math.max(size * 0.12, 1.5),
borderRadius: size,
backgroundColor: color,
};
return (
);
};
export const MenuGlyph = ({size = 20, color = '#000', testID}: GlyphProps) => {
const bar = {
width: size * 0.8,
height: Math.max(size * 0.1, 1.5),
borderRadius: size,
backgroundColor: color,
marginVertical: size * 0.09,
};
return (
);
};
type ChevronProps = GlyphProps & {direction?: 'up' | 'down' | 'left' | 'right'};
const CHEVRON_ROTATION = {
right: '45deg',
down: '135deg',
left: '225deg',
up: '315deg',
};
export const ChevronGlyph = ({
size = 20,
color = '#000',
direction = 'right',
testID,
}: ChevronProps) => (
);
export const SearchGlyph = ({
size = 20,
color = '#000',
testID,
}: GlyphProps) => (
);
type EyeProps = GlyphProps & {off?: boolean};
export const EyeGlyph = ({
size = 20,
color = '#000',
off,
testID,
}: EyeProps) => (
{off && (
)}
);
type CheckedProps = GlyphProps & {checked?: boolean};
export const CheckBoxGlyph = ({
size = 20,
color = '#000',
checked,
testID,
}: CheckedProps) => (
{checked && }
);
export const RadioGlyph = ({
size = 20,
color = '#000',
checked,
testID,
}: CheckedProps) => (
{checked && (
)}
);
export type RatingVariant = 'full' | 'half' | 'empty';
type ShapeProps = GlyphProps & {
variant?: RatingVariant;
shape?: 'star' | 'heart';
};
// U+FE0E forces text presentation so browsers do not swap the glyph for an emoji.
const SHAPES = {
star: {full: '★\uFE0E', empty: '☆\uFE0E'},
heart: {full: '♥\uFE0E', empty: '♡\uFE0E'},
};
/** Star or heart drawn with text glyphs; `half` overlays a clipped full shape. */
export const RatingGlyph = ({
size = 20,
color = '#000',
variant = 'full',
shape = 'star',
testID,
}: ShapeProps) => {
const glyphStyle = {
fontSize: size,
lineHeight: size * 1.15,
color,
includeFontPadding: false,
};
const {full, empty} = SHAPES[shape];
return (
{variant === 'full' ? full : empty}
{variant === 'half' && (
{full}
)}
);
};
const styles = StyleSheet.create({
rotate45: {transform: [{rotate: '45deg'}]},
rotateMinus45: {transform: [{rotate: '-45deg'}]},
rotate90: {transform: [{rotate: '90deg'}]},
});