Skip to content

Commit

Permalink
feat(Upload): text and title is possible to remove (#4163)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored Oct 22, 2024
1 parent 9bf9b9e commit b6db4a4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,14 @@ export const UploadDisabledFileMaxSize = () => (
/>
</ComponentBox>
)

export const UploadNoTitleNoText = () => (
<ComponentBox data-visual-test="upload-no-title-no-text">
<Upload
title={false}
text={false}
acceptedFileTypes={['jpg', 'png']}
id="upload-no-title-no-text"
/>
</ComponentBox>
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UploadDisabledFileMaxSize,
UploadFileMaxSizeBasedOnFileType,
UploadFileMaxSizeBasedOnFileTypeDisabled,
UploadNoTitleNoText,
} from 'Docs/uilib/components/upload/Examples'

## Demos
Expand Down Expand Up @@ -75,3 +76,7 @@ This can also be used to manually implement more complex file max size verificat
<VisibleWhenNotVisualTest>
<UploadDisabledFileMaxSize />
</VisibleWhenNotVisualTest>

### Upload without title and text

<UploadNoTitleNoText />
4 changes: 2 additions & 2 deletions packages/dnb-eufemia/src/components/upload/UploadDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const UploadProperties: PropertiesTableProps = {
status: 'optional',
},
title: {
doc: 'Custom text property. Replaces the default title.',
doc: 'Custom text property. Replaces the default title. Can be disabled using `false`.',
type: 'string',
status: 'optional',
},
text: {
doc: 'Custom text property. Replaces the default text.',
doc: 'Custom text property. Replaces the default text. Can be disabled using `false`.',
type: 'string',
status: 'optional',
},
Expand Down
10 changes: 6 additions & 4 deletions packages/dnb-eufemia/src/components/upload/UploadInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ const UploadInfo = () => {

return (
<>
<Lead space="0">{title}</Lead>
{title && <Lead space="0">{title}</Lead>}

<P top="xx-small" className="dnb-upload__text">
{text}
</P>
{text && (
<P top="xx-small" className="dnb-upload__text">
{text}
</P>
)}

{children}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ describe.each(['ui', 'sbanken'])('Upload for %s', (themeName) => {
})
expect(screenshot).toMatchImageSnapshot()
})

it('have to match when not providing title and text', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="upload-no-title-no-text"]',
})
expect(screenshot).toMatchImageSnapshot()
})
})

describe('Upload', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ describe('Upload', () => {
).toBeInTheDocument()
})

it('does not render text when text is false', () => {
render(<Upload {...defaultProps} text={false} />)

expect(screen.queryByText(nb.text)).not.toBeInTheDocument()
})

it('does not render text when text is empty string', () => {
render(<Upload {...defaultProps} text="" />)

expect(screen.queryByText(nb.text)).not.toBeInTheDocument()
})

it('does not render title when title is false', () => {
render(<Upload {...defaultProps} title={false} />)

expect(screen.queryByText(nb.title)).not.toBeInTheDocument()
})

it('does not render title when title is empty string', () => {
render(<Upload {...defaultProps} title="" />)

expect(screen.queryByText(nb.title)).not.toBeInTheDocument()
})

it('does not render fileTypeDescription when acceptedFileTypes is empty', () => {
const acceptedFileTypes = []

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6db4a4

Please sign in to comment.