Skip to content

Commit

Permalink
feat: add checkbox component (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Sep 19, 2023
1 parent 3cdb65d commit 235cfee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/components/Ory/Ui/Node/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isUiNodeInputAttributes,
} from "../../../../helpers/form"
import StyledTextInput from "../../../Styled/StyledTextInput"
import Checkbox from "../../../Styled/Checkbox"

interface Props extends InputProps {
node: UiNode
Expand Down Expand Up @@ -45,6 +46,8 @@ const guessVariant = ({ attributes }: UiNode) => {
return "button"
case "password":
return "password"
case "checkbox":
return "checkbox"
default:
return "text"
}
Expand Down Expand Up @@ -116,15 +119,24 @@ export const NodeInput = ({
return (
<View testID={`field/${name}`}>
<Title>{title}</Title>
<StyledTextInput
testID={name}
onChange={onChange}
value={value ? String(value) : ""}
editable={!disabled}
onChangeText={onChange}
state={disabled ? "disabled" : undefined}
{...extraProps}
/>
{variant === "checkbox" ? (
<Checkbox
testID={name}
onClick={() => onChange(!value)}
value={value}
disabled={disabled}
/>
) : (
<StyledTextInput
testID={name}
onChange={onChange}
value={value ? String(value) : ""}
editable={!disabled}
onChangeText={onChange}
state={disabled ? "disabled" : undefined}
{...extraProps}
/>
)}
<>
{node.messages?.map(({ text, id, type }, k) => (
<Subtitle key={`${id}${k}`} state={typeToState({ type, disabled })}>
Expand Down
3 changes: 3 additions & 0 deletions src/components/Styled/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styled from "styled-components/native"

export default styled.Switch({})

0 comments on commit 235cfee

Please sign in to comment.