-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MMI adds the note-to-trader component (#18106)
* MMI adds the note-to-trader component * MMI adds colors vars * MMI added component folder * MMI adds fireEvent * adds Box * review fixes * adds story * lint fix * prettier fix * prettier fix --------- Co-authored-by: Albert Olivé <[email protected]>
- Loading branch information
1 parent
0b83b13
commit 0a376fe
Showing
6 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
ui/components/institutional/note-to-trader/__snapshots__/note-to-trader.test.js.snap
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,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NoteToTrader should render the Note to trader component 1`] = ` | ||
<div> | ||
<div | ||
class="box note-header box--display-flex box--flex-direction-row box--justify-content-space-between" | ||
> | ||
<label | ||
class="box mm-text mm-label mm-label--html-for mm-text--body-md mm-text--font-weight-bold mm-text--color-text-default box--display-inline-flex box--flex-direction-row box--align-items-center" | ||
for="transaction-note" | ||
> | ||
Transaction note | ||
</label> | ||
<p | ||
class="box mm-text note-header__counter mm-text--body-md mm-text--color-text-default box--flex-direction-row" | ||
> | ||
9 | ||
/ | ||
280 | ||
</p> | ||
</div> | ||
<div | ||
class="box note-field box--display-flex box--flex-direction-column" | ||
> | ||
<textarea | ||
data-testid="transaction-note" | ||
id="transaction-note" | ||
maxlength="280" | ||
placeholder="" | ||
> | ||
some text | ||
</textarea> | ||
</div> | ||
</div> | ||
`; |
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 @@ | ||
export { default } from './note-to-trader'; |
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,23 @@ | ||
.note-header { | ||
line-height: 100%; | ||
margin: 0 0 5px 0; | ||
|
||
label { | ||
color: var(--black); | ||
margin: 0 0 4px 0; | ||
} | ||
} | ||
|
||
.note-field { | ||
textarea { | ||
min-height: 90px; | ||
border-radius: 5px; | ||
padding: 10px; | ||
font-size: 12px; | ||
resize: none; | ||
|
||
&::placeholder { | ||
color: var(--color-icon-alternative); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
ui/components/institutional/note-to-trader/note-to-trader.js
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,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
DISPLAY, | ||
FLEX_DIRECTION, | ||
JustifyContent, | ||
} from '../../../helpers/constants/design-system'; | ||
import { Label, Text } from '../../component-library'; | ||
import Box from '../../ui/box'; | ||
|
||
const NoteToTrader = (props) => { | ||
const { placeholder, maxLength, onChange, noteText, labelText } = props; | ||
|
||
return ( | ||
<> | ||
<Box | ||
className="note-header" | ||
display={DISPLAY.FLEX} | ||
justifyContent={JustifyContent.spaceBetween} | ||
> | ||
<Label htmlFor="transaction-note">{labelText}</Label> | ||
<Text className="note-header__counter"> | ||
{noteText.length}/{maxLength} | ||
</Text> | ||
</Box> | ||
<Box | ||
display={DISPLAY.FLEX} | ||
flexDirection={FLEX_DIRECTION.COLUMN} | ||
className="note-field" | ||
> | ||
<textarea | ||
id="transaction-note" | ||
data-testid="transaction-note" | ||
onChange={({ target: { value } }) => onChange(value)} | ||
autoFocus | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
value={noteText} | ||
/> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
NoteToTrader.propTypes = { | ||
placeholder: PropTypes.string, | ||
maxLength: PropTypes.string, | ||
onChange: PropTypes.func, | ||
noteText: PropTypes.string, | ||
labelText: PropTypes.string, | ||
}; | ||
|
||
export default NoteToTrader; |
21 changes: 21 additions & 0 deletions
21
ui/components/institutional/note-to-trader/note-to-trader.stories.js
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,21 @@ | ||
import React from 'react'; | ||
import NoteToTrader from '.'; | ||
|
||
export default { | ||
title: 'Components/Institutional/NoteToTrader', | ||
component: NoteToTrader, | ||
args: { | ||
placeholder: | ||
'The approver will see this note when approving the transaction at the custodian.', | ||
noteText: '', | ||
labelText: 'Transaction note', | ||
maxLength: '280', | ||
onChange: () => { | ||
/**/ | ||
}, | ||
}, | ||
}; | ||
|
||
export const DefaultStory = (args) => <NoteToTrader {...args} />; | ||
|
||
DefaultStory.storyName = 'NoteToTrader'; |
23 changes: 23 additions & 0 deletions
23
ui/components/institutional/note-to-trader/note-to-trader.test.js
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,23 @@ | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
import NoteToTrader from './note-to-trader'; | ||
|
||
describe('NoteToTrader', () => { | ||
it('should render the Note to trader component', () => { | ||
const props = { | ||
placeholder: '', | ||
maxLength: '280', | ||
noteText: 'some text', | ||
labelText: 'Transaction note', | ||
onChange: sinon.spy(), | ||
}; | ||
|
||
const { getByTestId, container } = render(<NoteToTrader {...props} />); | ||
|
||
fireEvent.change(getByTestId('transaction-note')); | ||
expect(getByTestId('transaction-note').value).toBe('some text'); | ||
expect(getByTestId('transaction-note')).toBeDefined(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |