-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from skorphil/update-institution-scenario
Implemented update institution scenario
- Loading branch information
Showing
10 changed files
with
277 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const formatCurrency = (assetName, event) => { | ||
const modifiedValue = event.target.value.toUpperCase(); | ||
setValue(`${assetName}.currency`, modifiedValue); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,58 @@ | ||
## Altering components style in chakra ui | ||
[Build your own design system with chakraui | Youtube](https://youtu.be/epJuxo8FKFA?si=UEmVtkfPLerimLkN&t=1210) | ||
|
||
The fundamental approach: | ||
1. Create components style file, according to Chakra style API | ||
2. Use methods `definePartsStyle`, `defineMultiStyleConfig` | ||
3. extend chacra's `theme` appending component styles with `extendTheme` ([theme.js](app/ChakraTheme.js)) | ||
4. pass `theme` as prop to `ChakraProvider` | ||
|
||
|
||
Tabs is a multipart component - [chackra docs | styling-multipart-components](https://chakra-ui.com/docs/styled-system/component-style#styling-multipart-components) and require `definePartsStyle`, `defineMultiStyleConfig` methods | ||
|
||
|
||
- [ ] How to use props do be passed to styles? | ||
|
||
Chakra tab custom styles | ||
```js | ||
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"; | ||
const { definePartsStyle, defineMultiStyleConfig } = | ||
createMultiStyleConfigHelpers(["tablist", "tab"]); | ||
|
||
export const tabsTheme = defineMultiStyleConfig({ | ||
variants: { | ||
grid: { | ||
tab: { | ||
borderRadius: "base", | ||
_selected: { | ||
bg: "black", | ||
}, | ||
## InstitutionTab | ||
### Props | ||
```diff | ||
//Props | ||
- isNew | ||
- isDeleted | ||
- isUpdated | ||
- text | ||
+ insitutionName (string) | ||
onRestore | ||
|
||
//Context | ||
+ fields from useFieldArray() | ||
+ getValue | ||
+ getFieldState | ||
``` | ||
|
||
justifyContent: "flex-start", | ||
}, | ||
tablist: { | ||
display: "grid", | ||
gridTemplateColumns: "repeat(auto-fit, minmax(100px,1fr))", | ||
gap: "3", | ||
w: "100%", | ||
}, | ||
}, | ||
}, | ||
}); | ||
### Listeners | ||
- restoreButton click | ||
|
||
### States | ||
```mermaid | ||
--- | ||
title: InstitutionTab | ||
--- | ||
stateDiagram-v2 | ||
direction LR | ||
[*] --> existing | ||
existing --> updated : prop changed | ||
updated --> existing : prop changed | ||
updated --> deleted : prop changed | ||
existing --> deleted : prop changed | ||
deleted --> updated : BUTTON_PRESS <br/> Do / setState | ||
deleted --> existing : BUTTON_PRESS <br/> Do / setState | ||
[*] --> new | ||
``` | ||
|
||
## Worklog | ||
### Deriving the states | ||
I want to minimize states number. By somehow derive from existing use-hook-form states | ||
|
||
ChakraTheme.js | ||
```js | ||
import { tabsTheme } from "../components/InstitutionTab/Tabs.chakra"; | ||
... | ||
const theme = extendTheme({ | ||
config, | ||
components: { | ||
Tabs: tabsTheme, | ||
}, | ||
}); | ||
#### New state | ||
Probably can be known via comparison between institution value and defaultValues(which are retrieved) | ||
For this scenario probably the simplest reliable way is to generate unique ID for institution and store it in db. | ||
|
||
export default theme; | ||
``` | ||
*defaultValues* can be retrieved from `fields` https://react-hook-form.com/docs/usefieldarray#:~:text=Description-,fields,-object%20%26%20%7B%20id | ||
|
||
if `institutions.ID.name` from `fields` === '' than institution is new | ||
|
||
## ForwardRef to extend component | ||
`forwardRef` https://chakra-ui.com/community/recipes/as-prop#option-1-using-forwardref-from-chakra-uireact | ||
#### Deleted state | ||
can be set by disabling institution fields | ||
|
||
Seems to work | ||
|
||
```js | ||
const IntitutionTab = forwardRef((props, ref) => ( | ||
<Tab px="4" py="5" rounded="sm" shadow="lg" ref={ref} {...props}> | ||
Custom Tab | ||
</Tab> | ||
)); | ||
... | ||
<IntitutionTab bg="red" /> | ||
``` | ||
#### Updated state | ||
can be retrived from `isDirty` | ||
|
||
```js | ||
const IntitutionTab = forwardRef( | ||
( | ||
{ name = "Unnamed institution", isDeleted = false, state = null, ...props }, | ||
ref | ||
) => { | ||
... | ||
<Tab | ||
isDisabled={isDeleted} | ||
paddingRight={rightSection && 1} | ||
className={`${classes.tab} ${isDeleted && classes.deleted}`} | ||
ref={ref} | ||
{...props} | ||
> | ||
``` | ||
### Text prop | ||
`text`(`InstitutionName`) can be retrieved by `getValues()`, **but there is problem of retreiving value from disabled inputs**(which i planned to use for deleted state) https://github.com/orgs/react-hook-form/discussions/11533 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
## Altering components style in chakra ui | ||
[Build your own design system with chakraui | Youtube](https://youtu.be/epJuxo8FKFA?si=UEmVtkfPLerimLkN&t=1210) | ||
|
||
The fundamental approach: | ||
1. Create components style file, according to Chakra style API | ||
2. Use methods `definePartsStyle`, `defineMultiStyleConfig` | ||
3. extend chacra's `theme` appending component styles with `extendTheme` ([theme.js](app/ChakraTheme.js)) | ||
4. pass `theme` as prop to `ChakraProvider` | ||
|
||
|
||
Tabs is a multipart component - [chackra docs | styling-multipart-components](https://chakra-ui.com/docs/styled-system/component-style#styling-multipart-components) and require `definePartsStyle`, `defineMultiStyleConfig` methods | ||
|
||
|
||
- [ ] How to use props do be passed to styles? | ||
|
||
Chakra tab custom styles | ||
```js | ||
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"; | ||
const { definePartsStyle, defineMultiStyleConfig } = | ||
createMultiStyleConfigHelpers(["tablist", "tab"]); | ||
|
||
export const tabsTheme = defineMultiStyleConfig({ | ||
variants: { | ||
grid: { | ||
tab: { | ||
borderRadius: "base", | ||
_selected: { | ||
bg: "black", | ||
}, | ||
|
||
justifyContent: "flex-start", | ||
}, | ||
tablist: { | ||
display: "grid", | ||
gridTemplateColumns: "repeat(auto-fit, minmax(100px,1fr))", | ||
gap: "3", | ||
w: "100%", | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
|
||
ChakraTheme.js | ||
```js | ||
import { tabsTheme } from "../components/InstitutionTab/Tabs.chakra"; | ||
... | ||
const theme = extendTheme({ | ||
config, | ||
components: { | ||
Tabs: tabsTheme, | ||
}, | ||
}); | ||
|
||
export default theme; | ||
``` | ||
|
||
|
||
## ForwardRef to extend component | ||
`forwardRef` https://chakra-ui.com/community/recipes/as-prop#option-1-using-forwardref-from-chakra-uireact | ||
|
||
Seems to work | ||
|
||
```js | ||
const IntitutionTab = forwardRef((props, ref) => ( | ||
<Tab px="4" py="5" rounded="sm" shadow="lg" ref={ref} {...props}> | ||
Custom Tab | ||
</Tab> | ||
)); | ||
... | ||
<IntitutionTab bg="red" /> | ||
``` | ||
|
||
```js | ||
const IntitutionTab = forwardRef( | ||
( | ||
{ name = "Unnamed institution", isDeleted = false, state = null, ...props }, | ||
ref | ||
) => { | ||
... | ||
<Tab | ||
isDisabled={isDeleted} | ||
paddingRight={rightSection && 1} | ||
className={`${classes.tab} ${isDeleted && classes.deleted}`} | ||
ref={ref} | ||
{...props} | ||
> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.