Skip to content

Commit

Permalink
feat(closeicon): add closeicon component
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bien committed Jan 12, 2021
1 parent 2f8d0e6 commit 1914d8a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
24 changes: 6 additions & 18 deletions src/Icons/ChevronIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ const ChevronIcon = ({
}: Props) => {
const theme = useContext(ThemeContext);

const segmentSizes = new Array(segments).fill(null).map((_, i) => 1 + i * 2);
let segmentSizes = new Array(segments).fill(null).map((_, i) => 1 + i * 2);

if (['right', 'bottom'].includes(direction)) {
segmentSizes = segmentSizes.reverse();
}
const isHorizontal = ['left', 'right'].includes(direction);

const SegmentPixel = () => (
Expand All @@ -47,27 +50,12 @@ const ChevronIcon = ({
/>
);

const getFlexDirection = () => {
switch (direction) {
case 'left':
return 'row';
case 'top':
return 'column';
case 'right':
return 'row-reverse';
case 'bottom':
return 'column-reverse';
default:
return 'row';
}
};

return (
<View
style={[
styles.wrapper,
{
flexDirection: getFlexDirection(),
flexDirection: isHorizontal ? 'row' : 'column',
},
style,
]}
Expand All @@ -85,7 +73,7 @@ const ChevronIcon = ({
},
]}
>
{i > 0 && <SegmentPixel />}
{segmentSize !== 1 && <SegmentPixel />}
<SegmentPixel />
</View>
))}
Expand Down
38 changes: 38 additions & 0 deletions src/Icons/CloseIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';

import { ChevronIcon } from '..';

type Props = {
disabled?: boolean;
segments?: number;
style?: StyleProp<ViewStyle>;
};

const CloseIcon = ({
disabled = false,
segments = 4,
style,
...rest
}: Props) => {
return (
<View style={[styles.wrapper, style]} {...rest}>
<ChevronIcon disabled={disabled} segments={segments} direction='right' />
<ChevronIcon
disabled={disabled}
segments={segments}
direction='left'
style={{ marginLeft: -2, marginRight: 2 }}
/>
</View>
);
};

const styles = StyleSheet.create({
wrapper: {
alignItems: 'center',
flexDirection: 'row',
},
});

export default CloseIcon;
1 change: 1 addition & 0 deletions src/Icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as ArrowIcon } from './ArrowIcon';
export { default as ChevronIcon } from './ChevronIcon';
export { default as CheckmarkIcon } from './CheckmarkIcon';
export { default as CloseIcon } from './CloseIcon';
7 changes: 3 additions & 4 deletions src/Window/Window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StyleSheet, View, StyleProp, ViewStyle } from 'react-native';

import { ThemeContext } from '../common/theming/Theme';

import { Panel, Button, Text } from '..';
import { Panel, Button, Text, CloseIcon } from '..';

type Props = React.ComponentPropsWithRef<typeof View> & {
// TODO: allow for inserting custom buttons to title bar?
Expand Down Expand Up @@ -75,7 +75,7 @@ const Window = ({
</View>
{onClose && (
<Button onPress={onClose} style={[styles.button]}>
X
<CloseIcon />
</Button>
)}
</View>
Expand Down Expand Up @@ -120,8 +120,7 @@ const styles = StyleSheet.create({
button: {
height: 28,
width: 32,
paddingVertical: 0,
paddingHorizontal: 0,
padding: 0,
},
});

Expand Down

0 comments on commit 1914d8a

Please sign in to comment.