-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DateRange subcomponent; changed email max-width to 690
- Loading branch information
1 parent
c738cdd
commit f7cede4
Showing
11 changed files
with
113 additions
and
2 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
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
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
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,52 @@ | ||
import React, { FC, CSSProperties } from 'react' | ||
import { EditableElement } from 'src/ui/EditableElement' | ||
import { useIsCurrentlyActiveEmailPart } from '../CurrentlyActiveEmailPart' | ||
import { useEmailPartsContentFor } from '../EmailPartsContent' | ||
import { StyleDefaults, Text, Spacing } from '../styles' | ||
import { EmailBlock } from 'src/ui' | ||
|
||
const defaultValue = '[00/00/0000] - [00/00/0000]' | ||
|
||
const { Row } = EmailBlock | ||
|
||
export const useDateRangeValue = (id: string) => { | ||
return useEmailPartsContentFor(id, defaultValue) | ||
} | ||
|
||
export const DateRange: FC<EmailSubComponentProps> = ({ emailSubComponent }) => { | ||
const { activate } = useIsCurrentlyActiveEmailPart(emailSubComponent.id) | ||
const [value, setValue] = useDateRangeValue(emailSubComponent.id) | ||
|
||
return ( | ||
<Row | ||
elements={[ | ||
'cell', | ||
'table', | ||
'row', | ||
{ part: 'cell', style: cellContainerStyles, className: StyleDefaults.layout.narrow }, | ||
]} | ||
> | ||
<EditableElement | ||
element="h3" | ||
label="Date Range" | ||
onClick={activate} | ||
onFocus={activate} | ||
onValueChange={setValue} | ||
style={styles} | ||
value={value} | ||
/> | ||
</Row> | ||
) | ||
} | ||
|
||
const cellContainerStyles: CSSProperties = { | ||
...StyleDefaults.inline.colors, | ||
} | ||
|
||
const styles: CSSProperties = { | ||
...Text.header.h3.bold, | ||
lineHeight: 1, | ||
margin: 0, | ||
marginBottom: Spacing.size.tiny, | ||
padding: 0, | ||
} |
50 changes: 50 additions & 0 deletions
50
src/templates/EmailTemplateSubComponents/__tests__/DateRange.test.tsx
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,50 @@ | ||
import React from 'react' | ||
import { DateRange } from '../DateRange' | ||
import userEvent from '@testing-library/user-event' | ||
import { render } from '@testing-library/react' | ||
import { EmailTemplate } from 'src/appTypes' | ||
import { faker } from '@faker-js/faker' | ||
import { | ||
buildUniqueEmailSubComponent, | ||
emailPartWrapper, | ||
expectActiveEmailPartToBe, | ||
expectActiveEmailPartToNotBe, | ||
expectEmailPartContentFor, | ||
} from 'src/testHelpers' | ||
|
||
describe('Date Range', () => { | ||
let emailSubComponent: EmailTemplate.UniqueSubComponent | ||
|
||
beforeEach(() => { | ||
emailSubComponent = buildUniqueEmailSubComponent('Header', { kind: 'DateRange' }) | ||
}) | ||
|
||
it('is editable', async () => { | ||
const user = userEvent.setup() | ||
const { queryByText, getByLabelText, baseElement } = render( | ||
<DateRange emailSubComponent={emailSubComponent} />, | ||
{ wrapper: emailPartWrapper }, | ||
) | ||
|
||
const value = faker.lorem.words(4) | ||
const key = emailSubComponent.id | ||
const input = getByLabelText('Date Range') | ||
await user.clear(input) | ||
await user.type(input, value) | ||
|
||
expect(queryByText(value)).not.toBeNull() | ||
expectEmailPartContentFor(key, baseElement) | ||
}) | ||
|
||
it('activates when clicked', async () => { | ||
const user = userEvent.setup() | ||
const { getByLabelText, baseElement } = render( | ||
<DateRange emailSubComponent={emailSubComponent} />, | ||
{ wrapper: emailPartWrapper }, | ||
) | ||
const key = emailSubComponent.id | ||
expectActiveEmailPartToNotBe(key, baseElement) | ||
await user.click(getByLabelText('Date Range')) | ||
expectActiveEmailPartToBe(key, baseElement) | ||
}) | ||
}) |
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