mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 16:56:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import React from 'react';
 | |
| import tw from 'twin.macro';
 | |
| import { ServerContext } from '@/state/server';
 | |
| import styled from 'styled-components/macro';
 | |
| import Input from '@/components/elements/Input';
 | |
| 
 | |
| export const FileActionCheckbox = styled(Input)`
 | |
|     && {
 | |
|         ${tw`border-neutral-500 bg-transparent`};
 | |
| 
 | |
|         &:not(:checked) {
 | |
|             ${tw`hover:border-neutral-300`};
 | |
|         }
 | |
|     }
 | |
| `;
 | |
| 
 | |
| export default ({ name }: { name: string }) => {
 | |
|     const isChecked = ServerContext.useStoreState((state) => state.files.selectedFiles.indexOf(name) >= 0);
 | |
|     const appendSelectedFile = ServerContext.useStoreActions((actions) => actions.files.appendSelectedFile);
 | |
|     const removeSelectedFile = ServerContext.useStoreActions((actions) => actions.files.removeSelectedFile);
 | |
| 
 | |
|     return (
 | |
|         <label css={tw`flex-none px-4 py-2 absolute self-center z-30 cursor-pointer`}>
 | |
|             <FileActionCheckbox
 | |
|                 name={'selectedFiles'}
 | |
|                 value={name}
 | |
|                 checked={isChecked}
 | |
|                 type={'checkbox'}
 | |
|                 onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
 | |
|                     if (e.currentTarget.checked) {
 | |
|                         appendSelectedFile(name);
 | |
|                     } else {
 | |
|                         removeSelectedFile(name);
 | |
|                     }
 | |
|                 }}
 | |
|             />
 | |
|         </label>
 | |
|     );
 | |
| };
 | 
