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

feat(Upload): text and title is possible to remove #4163

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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.
Loading