Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support react components #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gbrvalerio
Copy link

@gbrvalerio gbrvalerio commented Oct 12, 2022

Adds support for custom segments using the new prop SegmentComponent (which is any component that complies with SegmentProps). The api remains unchanged. As a breaking change it will be better in the future if its possible to remove all references to any styling from the props and let any custom styling be handled by the SegmentComponent itself

@gbrvalerio gbrvalerio closed this Oct 12, 2022
@gbrvalerio gbrvalerio reopened this Oct 12, 2022
@gbrvalerio
Copy link
Author

example usage:

const DateTimeSegment: React.FC<SegmentProps> = ({ segment, selected }) => {
  return (
    <View style={{ justifyContent: 'center', alignItems: 'center' }}>
      <SegmentTitle selected={selected}>
        {segment === 'start-time' ? 'Start Time' : 'End Time'}
      </SegmentTitle>¼
      <SegmentTime selected={selected}>8:00 AM</SegmentTime>
    </View>
  );
};

const DateTimeSelector: React.FC<{}> = () => {
  const [currentIndex, setCurrentIndex] = useState(0);
  return (
    <>
      <InstructionText>{localization.editSchedule_selectTime}</InstructionText>
      <SegmentedControl
        containerMargin={16}
        segments={['start-time', 'end-time']}
        currentIndex={currentIndex}
        onChange={index => setCurrentIndex(index)}
        SegmentComponent={DateTimeSegment}
      />
    </>
  );
};

InstructionText, SegmentTime, SegmentTitle are styled-component components but you can get the feeling
Screen Shot 2022-10-13 at 11 50 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant