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

42 add typescript #104

Merged
merged 18 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"jsx": "react",
"baseUrl": ".",
"paths": {
"@": ["src"],
Expand Down
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
},
"devDependencies": {
"@types/react": "^18.0.18",
"@types/styled-components": "^5.1.26",
"@vitejs/plugin-react": "^2.1.0",
"compass-mixins": "^0.12.12",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.31.7",
"prettier": "2.7.1",
"sass": "^1.54.8",
"typescript": "^5.0.4",
"vite": "^3.0.7"
}
}
File renamed without changes.
11 changes: 8 additions & 3 deletions src/components/BankCard.jsx → src/components/BankCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react';
import banksData from '../constants/bankData';
import S from 'styled-components';

function BankCard({bankNumber}) {
interface BankCardProps {
bankNumber: string;
}

const bankName = banksData[bankNumber]?.name ?? 'Nepostojeća banka';
const BankCard:React.FC<BankCardProps> = ({bankNumber}) => {

const bank = banksData.find((item) => item.bankNumber === bankNumber) ;

return (
<BankCardWrapper>
<BankName>Ovaj račun pripada: {bankName}</BankName>
<BankName>Ovaj račun pripada: {bank?.name ?? 'Nepostojeća banka'}</BankName>
</BankCardWrapper>
)}

Expand Down
13 changes: 0 additions & 13 deletions src/components/ErrorMessage.jsx

This file was deleted.

19 changes: 19 additions & 0 deletions src/components/ErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import S from 'styled-components'

interface ErrorMessageProps {
id: string;
errorMessage: string;
}

const ErrorMessage:React.FC<ErrorMessageProps> = ({ id, errorMessage }) => <StyledErrorMessage id={id}>{errorMessage}</StyledErrorMessage>

const StyledErrorMessage = S.p`
display: none;
margin-top: 0.5rem;
color: red;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
`

export default ErrorMessage
25 changes: 21 additions & 4 deletions src/components/Input.jsx → src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import React from 'react';
import { deviceBrakepoints } from '../config/device-brakepoints'
import Label from './Label.jsx'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove .jsx

import S from 'styled-components'
import { deviceBrakepoints } from '@config/device-brakepoints.jsx'

const Input = ({ type = 'text', id, help, helpText, disabled, width, label, value, whenChanged }) => (
interface InputProps {
type?: string;
id: string;
help: string;
helpText: string;
disabled?: boolean;
width: number;
label: string;
value: string | number;
whenChanged: (e:any) => void;
Copy link
Member

@itmilos itmilos Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenChanged: (e: React.ChangeEvent<HTMLInputElement>) => void;
}

};

const Input:React.FC<InputProps> = ({ type = 'text', id, help, helpText, disabled, width, label, value, whenChanged }) => (
<Container width={width} >
<Label label={label} for={id}/>
<Label label={label} forId={id}/>
<InnerInput type={type} name={id} id={id} aria-describedby={help} disabled={disabled} value={value} onChange={whenChanged} />
<span hidden id={help}>{helpText}</span>
</Container>
)

const Container = S.div`
interface ContainerProps {
width: number;
};

const Container = S.div<ContainerProps>`
display: inline-block;
text-align: left;
margin-bottom: 7px;
Expand Down
20 changes: 16 additions & 4 deletions src/components/InputGroup.jsx → src/components/InputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import ErrorMessage from './ErrorMessage.jsx'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove .jsx

import React from 'react'
import ErrorMessage from './ErrorMessage.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove .js

import S from 'styled-components'
import { useState } from 'react'
import { InputsProps } from './SplittedInput.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itmilos I do not know why is that happening. The app is constantly injecting .jsx imports


const InputGroup = ({ input, index }) => {
interface InputGroupProps {
input: InputsProps;
index: number;
}

const InputGroup:React.FC<InputGroupProps> = ({ input, index }) => {
const [focused, setFocused] = useState(false)

const handleFocus = event => {
const handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {
setFocused(true)
if (input?.appendZeros && event.target.value.length < 13) input.appendZeros(event.target.value)
}

return (
<StyledInputGroup width={input.width}>
<StyledInput
Expand All @@ -27,7 +35,11 @@ const InputGroup = ({ input, index }) => {
)
}

const StyledInputGroup = S.div`
interface StyledInputGroup {
width: number;
};

const StyledInputGroup = S.div<StyledInputGroup>`
width: ${props => (props.width ? props.width : '100')}%;
display: inline-block;
`
Expand Down
8 changes: 7 additions & 1 deletion src/components/Label.jsx → src/components/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from 'react'
import S from 'styled-components'

const Label = ({ label }) => <StyledLabel htmlFor={label}>{label}</StyledLabel>
interface LabelProps {
label: string;
forId?: string;
}

const Label:React.FC<LabelProps> = ({ label, forId }) => <StyledLabel htmlFor={forId}>{label}</StyledLabel>

const StyledLabel = S.label`
display: block;
Expand Down
13 changes: 9 additions & 4 deletions src/components/Modal.jsx → src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, { useEffect } from 'react'
import S from 'styled-components';

const Modal = ({closeModal, children}) => {
interface ModalProps {
closeModal: () => void;
children: React.ReactNode;
}

const Modal:React.FC<ModalProps> = ({closeModal, children}) => {

const handleClickOutside = (event) => {
const target = event.target;
if (target.id === 'backdrop') {
const handleClickOutside = (event: MouseEvent) => {
const target = event.target as HTMLElement;
if (target?.id === 'backdrop') {
closeModal()
}
};
Expand Down
32 changes: 25 additions & 7 deletions src/components/Modelselect.jsx → src/components/Modelselect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Label from './Label.jsx'
import S from 'styled-components'
import Select from 'react-select'
import React from 'react'
import { ModelCodeOptionsType, PayCodeOptionsType } from '../constants/type.js'

const ModelselectStyles = {
control: styles => ({
control: (styles: any) => ({
...styles,
borderRadius: '0',
backgroundColor: 'lightgrey',
Expand All @@ -12,23 +14,23 @@ const ModelselectStyles = {
boxShadow: 'none',
top: '-1px'
}),
menu: styles => ({
menu: (styles: any) => ({
...styles,
white: '200px'
}),
menuList: styles => ({
menuList: (styles: any) => ({
...styles,
background: 'white',
color: 'lightgray'
}),
option: (styles, { isFocused, isSelected }) => ({
option: (styles: any, { isFocused, isSelected }: any) => ({
...styles,
background: isFocused ? 'gray' : isSelected ? 'lightgrey' : 'undefined',
zIndex: 1
})
}

const theme = theme => ({
const theme = (theme: { colors: any; spacing: any }) => ({
...theme,
colors: {
...theme.colors,
Expand All @@ -44,7 +46,20 @@ const theme = theme => ({
}
})

const Modelselect = ({ width, placeholder, helpId, helpText, label, value, whenChanged, options }) => (
interface ModelselectProps {
width: number;
placeholder: string;
helpId: string;
helpText:string;
label: string;
value: string;
whenChanged: (e:any) => void;
options: PayCodeOptionsType[] | ModelCodeOptionsType[];
}



const Modelselect:React.FC<ModelselectProps> = ({ width, placeholder, helpId, helpText, label, value, whenChanged, options }) => (
<Container width={width}>
<Label label={label} />
<Select
Expand All @@ -61,8 +76,11 @@ const Modelselect = ({ width, placeholder, helpId, helpText, label, value, whenC
<span hidden id={helpId}>{helpText}</span>
</Container>
)
interface ContainerProps {
width: number;
};

const Container = S.div`
const Container = S.div<ContainerProps>`
display: inline-block;
text-align: left;
margin-bottom: 7px;
Expand Down
Loading