All files / src/stories PhotoChooser.stories.tsx

0% Statements 0/18
0% Branches 0/7
0% Functions 0/8
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70                                                                                                                                           
import React, { useState } from 'react';
 
import { Story } from '@storybook/react';
 
import PhotoChooser, { PhotoChooserProps } from '../components/PhotoChooser';
 
const SAMPLE_IMAGE =
  'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120"><rect width="120" height="120" fill="%234f8a5b"/></svg>';
 
export default {
  title: 'PhotoChooser',
  component: PhotoChooser,
};
 
const Template: Story<PhotoChooserProps> = (args) => {
  return <PhotoChooser {...args} />;
};
 
export const Default = Template.bind({});
Default.args = {
  onPhotosChanged: (data) => data.length && window.alert('Photo selected!'),
  multipleSelection: false,
  uploadText: 'Upload a photo',
  uploadDescription: 'Select any photo from your device',
  photoSelectedText: 'Photo selected',
  chooseFileText: 'Choose file',
  replaceFileText: 'Replace file',
};
 
export const Multiple = Template.bind({});
Multiple.args = {
  onPhotosChanged: (data) => data.length && window.alert(`${data.length} photos changed (added or deleted)`),
  multipleSelection: true,
  uploadText: 'Upload a photo',
  uploadDescription: 'Select any photo from your device',
  photoSelectedText: 'Photo selected',
  chooseFileText: 'Choose file',
  replaceFileText: 'Replace file',
  error: { title: 'Select photos please', text: 'Error selecting' },
};
 
const ExistingTemplate: Story<PhotoChooserProps & { initialExistingPhotos?: string[] }> = ({
  initialExistingPhotos = [],
  ...args
}) => {
  const [existingPhotos, setExistingPhotos] = useState<string[]>(initialExistingPhotos);
 
  return (
    <PhotoChooser
      {...args}
      existingPhotos={existingPhotos}
      onExistingPhotoRemoved={(index) => setExistingPhotos((prev) => prev.filter((_, i) => i !== index))}
    />
  );
};
 
export const WithExistingImages = ExistingTemplate.bind({});
WithExistingImages.args = {
  onPhotosChanged: (data) => data.length && window.alert(`${data.length} new photos`),
  multipleSelection: true,
  initialExistingPhotos: [SAMPLE_IMAGE],
  existingImagesLabel: 'Existing images',
  newImagesLabel: 'New images',
  uploadText: 'Upload a photo',
  uploadDescription: 'Select any photo from your device',
  photoSelectedText: 'Photo selected',
  chooseFileText: 'Choose file',
  replaceFileText: 'Replace file',
};