Skip to content

Commit

Permalink
feat: support theme in textInput
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Nov 24, 2021
1 parent 7b3a0fa commit d59a102
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/component/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./atoms";
export * from "./molecules";
export * from "./muscles";
1 change: 0 additions & 1 deletion packages/component/src/molecules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./loadingView";
export * from "./scrollView";
export * from "./text";
export * from "./textInput";
1 change: 1 addition & 0 deletions packages/component/src/muscles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./textInput";
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import jss from "jss";
import * as React from "react";
import { composeRef, useElementLayout } from "reactjs-view-core";
import { flattenStyle } from "../../atoms";
import { useThemes } from "../../molecules/text/styles";
import TextInputState from "./TextInputState";
import { TextInputProps } from "./types";

Expand Down Expand Up @@ -43,6 +44,7 @@ const TextInput = React.forwardRef<HTMLElement, TextInputProps>(
blurOnSubmit,
clearTextOnFocus,
dir,
theme = "regular-fa",
editable = true,
keyboardType = "default",
multiline = false,
Expand Down Expand Up @@ -70,6 +72,7 @@ const TextInput = React.forwardRef<HTMLElement, TextInputProps>(
) => {
let type: React.InputHTMLAttributes<HTMLInputElement>["type"];
let inputMode: React.HTMLAttributes<HTMLInputElement>["inputMode"];
const themes = useThemes();

switch (keyboardType) {
case "email-address":
Expand Down Expand Up @@ -277,7 +280,11 @@ const TextInput = React.forwardRef<HTMLElement, TextInputProps>(
supportedProps.autoCapitalize = autoCapitalize;
supportedProps.autoComplete = autoComplete || autoCompleteType || "on";
supportedProps.autoCorrect = autoCorrect ? "on" : "off";
supportedProps.className = classNames(classes.textinput, className);
supportedProps.className = classNames(
classes.textinput,
themes[theme],
className,
);
// 'auto' by default allows browsers to infer writing direction
supportedProps.dir = dir !== undefined ? dir : "auto";
supportedProps.enterKeyHint = returnKeyType;
Expand Down Expand Up @@ -318,7 +325,7 @@ const classes = jss
border: "0 solid black",
borderRadius: 0,
boxSizing: "border-box",
font: "14px System",
fontSize: 14,
margin: 0,
padding: 0,
resize: "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

import React from "react";
import { ViewProps } from "../../atoms";
import { TextProps } from "../../molecules";

export interface TextInputProps extends Omit<ViewProps, "autoCorrect"> {
autoCapitalize?: "characters" | "none" | "sentences" | "words";
theme?: TextProps["theme"];
autoComplete?: string;
autoCompleteType?: string; // Compat with React Native (Bug react-native#26003)
autoCorrect?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/stories/src/base/textInput/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const Template: Story<TextInputProps> = (args) => (
export const Regular = Template.bind({});

Regular.args = {
placeholder: "placeholder",
placeholder: "متن پس زمینه",
placeholderTextColor: "red",
};

export const Multiline = Template.bind({});

Multiline.args = {
placeholder: "placeholder",
placeholder: "متن پس زمینه",
numberOfLines: 2,
multiline: true,
};

0 comments on commit d59a102

Please sign in to comment.