diff --git a/src/ArrowIcon/index.ts b/src/ArrowIcon/index.ts deleted file mode 100644 index a31a511..0000000 --- a/src/ArrowIcon/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './ArrowIcon'; diff --git a/src/ArrowIcon/ArrowIcon.tsx b/src/Icons/ArrowIcon.tsx similarity index 96% rename from src/ArrowIcon/ArrowIcon.tsx rename to src/Icons/ArrowIcon.tsx index ad2b1b6..86f5538 100644 --- a/src/ArrowIcon/ArrowIcon.tsx +++ b/src/Icons/ArrowIcon.tsx @@ -53,8 +53,8 @@ const ArrowIcon = ({ ? theme.materialTextDisabledShadow : 'transparent', shadowOffset: { - width: 1, - height: 1, + width: pixelSize, + height: pixelSize, }, shadowOpacity: 1, shadowRadius: 0, diff --git a/src/Icons/CheckmarkIcon.tsx b/src/Icons/CheckmarkIcon.tsx new file mode 100644 index 0000000..b3fcaae --- /dev/null +++ b/src/Icons/CheckmarkIcon.tsx @@ -0,0 +1,49 @@ +import React, { useContext } from 'react'; +import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; +import { ThemeContext } from '../common/theming/Theme'; + +type Props = { + disabled?: boolean; + style?: StyleProp; +}; + +const pixelSize = 1.5; +const segmentSize = 3 * pixelSize; + +const CheckmarkIcon = ({ disabled = false, style = {}, ...rest }: Props) => { + const theme = useContext(ThemeContext); + + const segmentOffsets = [2, 3, 4, 3, 2, 1, 0]; + + return ( + + {segmentOffsets.map((offset, i) => ( + + ))} + + ); +}; + +const styles = StyleSheet.create({ + wrapper: { + position: 'relative', + flexDirection: 'row', + }, + segment: { + width: pixelSize, + height: segmentSize, + }, +}); + +export default CheckmarkIcon; diff --git a/src/Icons/index.ts b/src/Icons/index.ts new file mode 100644 index 0000000..7f0615e --- /dev/null +++ b/src/Icons/index.ts @@ -0,0 +1,2 @@ +export { default as ArrowIcon } from './ArrowIcon'; +export { default as CheckmarkIcon } from './CheckmarkIcon'; diff --git a/src/SwitchBase/SwitchBase.tsx b/src/SwitchBase/SwitchBase.tsx index 0242666..ea6f707 100644 --- a/src/SwitchBase/SwitchBase.tsx +++ b/src/SwitchBase/SwitchBase.tsx @@ -11,30 +11,10 @@ import { import { Border } from '../common/styleElements'; import { ThemeContext } from '../common/theming/Theme'; -import { Text } from '..'; +import { Text, CheckmarkIcon } from '..'; -const switchSize = 20; - -const symbols = { - checkbox: { - default: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAQ0lEQVQoU42Q0Q4AIARFj///6BqNSat4sXFcF6ER8mEGIC9IAY2AbCKpOnBAVgA2wIuac8MFQ/m6Ih9UjVdvy3njTUwR1AkKqm4yNwAAAABJRU5ErkJggg==', - disabled: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAR0lEQVQoU2NkIAIw4lPT0tryv6a6hhGnIpACkAFwRTAdMFNhCjAUwQTQFYDEwdYhS8BMA1kDY8MZ2EzAUAQzEdkErIpwBQcA7RckCvjAHfcAAAAASUVORK5CYII=', - }, - radio: { - default: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAKElEQVQoU2NkIAAYSVXwH6oBrhHZBJgkzFCwHEkKQBrwWoHVvQR9AQAfmgQJp08TYAAAAABJRU5ErkJggg==', - disabled: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAALUlEQVQoU2NkIAAYSVLQ0tryH6ShproGrhHOgEnCTIQpIl4BSCdeK3A5lqAvAEBkEAkDjL/SAAAAAElFTkSuQmCC', - }, - indeterminate: { - default: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAJElEQVQoU2NkYGD4z4AKGJG5IA4dFKA5AdVKFAdBVaK4iXIFAEiuCAWq9MdHAAAAAElFTkSuQmCC', - disabled: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAJElEQVQoU2NsaW35z4AEaqprGJH5jHRQgGwfiI1uJYqDaKMAAHKtGjlbjgHwAAAAAElFTkSuQmCC', - }, -}; +const checkboxSize = 20; +const radioSize = 20; export type SwitchStatus = 'checked' | 'unchecked' | 'indeterminate'; @@ -67,38 +47,28 @@ export const SwitchBase = ({ const theme = useContext(ThemeContext); const [isPressed, setIsPressed] = React.useState(false); const isRadio = component === 'radio'; + const switchSize = component === 'checkbox' ? checkboxSize : radioSize; const boxSize = variant === 'flat' ? switchSize - 4 : switchSize; const borderRadius = isRadio ? boxSize / 2 : 0; const renderCheckmark = () => { - const symbolOffset = variant === 'flat' ? 2 : 4; if (status === 'checked') { - const symbol = symbols[component][disabled ? 'disabled' : 'default']; - - return ( - + ) : ( + ); } if (status === 'indeterminate') { - const symbol = symbols[status][disabled ? 'disabled' : 'default']; - return ( ); @@ -189,6 +164,8 @@ const styles = StyleSheet.create({ }, switchSymbol: { marginRight: 4, + alignItems: 'center', + justifyContent: 'center', }, labelWrapper: { paddingHorizontal: 4, diff --git a/src/index.ts b/src/index.ts index 0105776..6be1608 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ export { default as AppBar } from './AppBar'; -export { default as ArrowIcon } from './ArrowIcon'; export { default as Button } from './Button'; export { default as Card } from './Card'; export { default as Checkbox } from './Checkbox'; @@ -26,6 +25,7 @@ export { default as Window } from './Window'; export { Select, SelectBox } from './Select'; export { Text, Title, Anchor } from './Typography'; +export * from './Icons'; export * from './common/theming'; export { Theme } from './types';