All files / laravel-saas/resources/js/stories/ui SelectAdvanced.stories.tsx

0% Statements 0/287
100% Branches 1/1
100% Functions 1/1
0% Lines 0/287

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
import type { Meta, StoryObj } from '@storybook/react';
import {
    Select,
    SelectContent,
    SelectGroup,
    SelectItem,
    SelectLabel,
    SelectTrigger,
    SelectValue,
    SelectSeparator,
} from '@/Components/ui/SelectAdvanced';
import { useState } from 'react';
 
const meta = {
    title: 'UI/SelectAdvanced',
    component: Select,
    parameters: {
        layout: 'centered',
    },
    tags: ['autodocs'],
} satisfies Meta<typeof Select>;
 
export default meta;
type Story = StoryObj<typeof meta>;
 
export const Default: Story = {
    render: () => (
        <Select>
            <SelectTrigger className="w-[180px]">
                <SelectValue placeholder="Select a fruit" />
            </SelectTrigger>
            <SelectContent>
                <SelectItem value="apple">Apple</SelectItem>
                <SelectItem value="banana">Banana</SelectItem>
                <SelectItem value="blueberry">Blueberry</SelectItem>
                <SelectItem value="grapes">Grapes</SelectItem>
                <SelectItem value="pineapple">Pineapple</SelectItem>
            </SelectContent>
        </Select>
    ),
};
 
export const WithGroups: Story = {
    render: () => (
        <Select>
            <SelectTrigger className="w-[280px]">
                <SelectValue placeholder="Select a timezone" />
            </SelectTrigger>
            <SelectContent>
                <SelectGroup>
                    <SelectLabel>North America</SelectLabel>
                    <SelectItem value="est">Eastern Standard Time (EST)</SelectItem>
                    <SelectItem value="cst">Central Standard Time (CST)</SelectItem>
                    <SelectItem value="mst">Mountain Standard Time (MST)</SelectItem>
                    <SelectItem value="pst">Pacific Standard Time (PST)</SelectItem>
                </SelectGroup>
                <SelectSeparator />
                <SelectGroup>
                    <SelectLabel>Europe & Africa</SelectLabel>
                    <SelectItem value="gmt">Greenwich Mean Time (GMT)</SelectItem>
                    <SelectItem value="cet">Central European Time (CET)</SelectItem>
                    <SelectItem value="eet">Eastern European Time (EET)</SelectItem>
                    <SelectItem value="west">Western European Summer Time (WEST)</SelectItem>
                </SelectGroup>
                <SelectSeparator />
                <SelectGroup>
                    <SelectLabel>Asia</SelectLabel>
                    <SelectItem value="ist">India Standard Time (IST)</SelectItem>
                    <SelectItem value="cst_china">China Standard Time (CST)</SelectItem>
                    <SelectItem value="jst">Japan Standard Time (JST)</SelectItem>
                    <SelectItem value="kst">Korea Standard Time (KST)</SelectItem>
                </SelectGroup>
            </SelectContent>
        </Select>
    ),
};
 
export const Controlled: Story = {
    render: () => {
        const Component = () => {
            const [value, setValue] = useState('');
 
            return (
                <div className="space-y-4">
                    <Select value={value} onValueChange={setValue}>
                        <SelectTrigger className="w-[200px]">
                            <SelectValue placeholder="Select a color" />
                        </SelectTrigger>
                        <SelectContent>
                            <SelectItem value="red">Red</SelectItem>
                            <SelectItem value="green">Green</SelectItem>
                            <SelectItem value="blue">Blue</SelectItem>
                            <SelectItem value="yellow">Yellow</SelectItem>
                            <SelectItem value="purple">Purple</SelectItem>
                            <SelectItem value="orange">Orange</SelectItem>
                        </SelectContent>
                    </Select>
                    <p className="text-sm text-muted-foreground">
                        Selected value: {value || 'none'}
                    </p>
                    <button
                        onClick={() => setValue('blue')}
                        className="px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md"
                    >
                        Set to Blue
                    </button>
                </div>
            );
        };
 
        return <Component />;
    },
};
 
export const Disabled: Story = {
    render: () => (
        <div className="flex gap-4">
            <Select disabled>
                <SelectTrigger className="w-[180px]">
                    <SelectValue placeholder="Disabled select" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="apple">Apple</SelectItem>
                    <SelectItem value="banana">Banana</SelectItem>
                    <SelectItem value="blueberry">Blueberry</SelectItem>
                </SelectContent>
            </Select>
 
            <Select>
                <SelectTrigger className="w-[180px]">
                    <SelectValue placeholder="Select a fruit" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="apple">Apple</SelectItem>
                    <SelectItem value="banana" disabled>
                        Banana (out of stock)
                    </SelectItem>
                    <SelectItem value="blueberry">Blueberry</SelectItem>
                </SelectContent>
            </Select>
        </div>
    ),
};
 
export const LongList: Story = {
    render: () => (
        <Select>
            <SelectTrigger className="w-[200px]">
                <SelectValue placeholder="Select a country" />
            </SelectTrigger>
            <SelectContent>
                {[
                    'Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola',
                    'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan',
                    'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus',
                    'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia',
                    'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria',
                    'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada',
                    'Cape Verde', 'Central African Republic', 'Chad', 'Chile', 'China',
                    'Colombia', 'Comoros', 'Congo', 'Costa Rica', 'Croatia',
                    'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti',
                ].map((country) => (
                    <SelectItem key={country} value={country.toLowerCase()}>
                        {country}
                    </SelectItem>
                ))}
            </SelectContent>
        </Select>
    ),
};
 
export const WithDefaultValue: Story = {
    render: () => (
        <Select defaultValue="blueberry">
            <SelectTrigger className="w-[180px]">
                <SelectValue />
            </SelectTrigger>
            <SelectContent>
                <SelectItem value="apple">Apple</SelectItem>
                <SelectItem value="banana">Banana</SelectItem>
                <SelectItem value="blueberry">Blueberry</SelectItem>
                <SelectItem value="grapes">Grapes</SelectItem>
                <SelectItem value="pineapple">Pineapple</SelectItem>
            </SelectContent>
        </Select>
    ),
};
 
export const InForm: Story = {
    render: () => {
        const Component = () => {
            const [formData, setFormData] = useState({
                name: '',
                role: '',
                department: '',
            });
 
            const handleSubmit = (e: React.FormEvent) => {
                e.preventDefault();
                alert(JSON.stringify(formData, null, 2));
            };
 
            return (
                <form onSubmit={handleSubmit} className="w-[400px] space-y-4">
                    <div>
                        <label htmlFor="name" className="block text-sm font-medium mb-2">
                            Name
                        </label>
                        <input
                            id="name"
                            type="text"
                            value={formData.name}
                            onChange={(e) => setFormData({ ...formData, name: e.target.value })}
                            className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
                            placeholder="Enter your name"
                            required
                        />
                    </div>
 
                    <div>
                        <label htmlFor="role" className="block text-sm font-medium mb-2">
                            Role
                        </label>
                        <Select
                            value={formData.role}
                            onValueChange={(value) => setFormData({ ...formData, role: value })}
                            required
                        >
                            <SelectTrigger id="role">
                                <SelectValue placeholder="Select your role" />
                            </SelectTrigger>
                            <SelectContent>
                                <SelectItem value="developer">Developer</SelectItem>
                                <SelectItem value="designer">Designer</SelectItem>
                                <SelectItem value="manager">Manager</SelectItem>
                                <SelectItem value="qa">QA Engineer</SelectItem>
                                <SelectItem value="devops">DevOps Engineer</SelectItem>
                            </SelectContent>
                        </Select>
                    </div>
 
                    <div>
                        <label htmlFor="department" className="block text-sm font-medium mb-2">
                            Department
                        </label>
                        <Select
                            value={formData.department}
                            onValueChange={(value) => setFormData({ ...formData, department: value })}
                            required
                        >
                            <SelectTrigger id="department">
                                <SelectValue placeholder="Select your department" />
                            </SelectTrigger>
                            <SelectContent>
                                <SelectGroup>
                                    <SelectLabel>Engineering</SelectLabel>
                                    <SelectItem value="frontend">Frontend</SelectItem>
                                    <SelectItem value="backend">Backend</SelectItem>
                                    <SelectItem value="fullstack">Fullstack</SelectItem>
                                    <SelectItem value="mobile">Mobile</SelectItem>
                                </SelectGroup>
                                <SelectSeparator />
                                <SelectGroup>
                                    <SelectLabel>Other</SelectLabel>
                                    <SelectItem value="design">Design</SelectItem>
                                    <SelectItem value="product">Product</SelectItem>
                                    <SelectItem value="marketing">Marketing</SelectItem>
                                    <SelectItem value="sales">Sales</SelectItem>
                                </SelectGroup>
                            </SelectContent>
                        </Select>
                    </div>
 
                    <button
                        type="submit"
                        className="w-full h-10 px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
                    >
                        Submit
                    </button>
                </form>
            );
        };
 
        return <Component />;
    },
};
 
export const CustomWidth: Story = {
    render: () => (
        <div className="flex flex-col gap-4">
            <Select>
                <SelectTrigger className="w-[100px]">
                    <SelectValue placeholder="Small" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="1">One</SelectItem>
                    <SelectItem value="2">Two</SelectItem>
                    <SelectItem value="3">Three</SelectItem>
                </SelectContent>
            </Select>
 
            <Select>
                <SelectTrigger className="w-[200px]">
                    <SelectValue placeholder="Medium" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="1">Option One</SelectItem>
                    <SelectItem value="2">Option Two</SelectItem>
                    <SelectItem value="3">Option Three</SelectItem>
                </SelectContent>
            </Select>
 
            <Select>
                <SelectTrigger className="w-[400px]">
                    <SelectValue placeholder="Large" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="1">This is a very long option that demonstrates text truncation</SelectItem>
                    <SelectItem value="2">Another long option with lots of text</SelectItem>
                    <SelectItem value="3">Yet another option with extended text content</SelectItem>
                </SelectContent>
            </Select>
 
            <Select>
                <SelectTrigger className="w-full">
                    <SelectValue placeholder="Full width" />
                </SelectTrigger>
                <SelectContent>
                    <SelectItem value="1">Full Width Option One</SelectItem>
                    <SelectItem value="2">Full Width Option Two</SelectItem>
                    <SelectItem value="3">Full Width Option Three</SelectItem>
                </SelectContent>
            </Select>
        </div>
    ),
};