Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mantinedev/mantine
- Loading branch information
Showing
6 changed files
with
94 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
src/mantine-demos/src/demos/core/FileButton/FileButton.demo.reset.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,67 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import { FileButton, Button, Group, Text } from '@mantine/core'; | ||
|
||
const code = ` | ||
import { useState, useRef } from 'react'; | ||
import { FileButton, Button, Group, Text } from '@mantine/core'; | ||
function Demo() { | ||
const [file, setFile] = useState<File | null>(null); | ||
const resetRef = useRef<() => void>(null); | ||
const clearFile = () => { | ||
setFile(null); | ||
resetRef.current?.(); | ||
}; | ||
return ( | ||
<> | ||
<Group position="center"> | ||
<FileButton resetRef={resetRef} onChange={setFile} accept="image/png,image/jpeg"> | ||
{(props) => <Button {...props}>Upload image</Button>} | ||
</FileButton> | ||
<Button disabled={!file} color="red" onClick={clearFile}>Reset</Button> | ||
</Group> | ||
{file && ( | ||
<Text size="sm" align="center" mt="sm"> | ||
Picked file: {file.name} | ||
</Text> | ||
)} | ||
</> | ||
); | ||
} | ||
`; | ||
|
||
function Demo() { | ||
const [file, setFile] = useState<File | null>(null); | ||
const resetRef = useRef<() => void>(null); | ||
|
||
const clearFile = () => { | ||
setFile(null); | ||
resetRef.current?.(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Group position="center"> | ||
<FileButton resetRef={resetRef} onChange={setFile} accept="image/png,image/jpeg"> | ||
{(props) => <Button {...props}>Upload image</Button>} | ||
</FileButton> | ||
<Button disabled={!file} color="red" onClick={clearFile}> | ||
Reset | ||
</Button> | ||
</Group> | ||
{file && ( | ||
<Text size="sm" align="center" mt="sm"> | ||
Picked file: {file.name} | ||
</Text> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export const reset: MantineDemo = { | ||
type: 'demo', | ||
component: Demo, | ||
code, | ||
}; |
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,2 +1,3 @@ | ||
export { usage } from './FileButton.demo.usage'; | ||
export { multiple } from './FileButton.demo.multiple'; | ||
export { reset } from './FileButton.demo.reset'; |