| 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 |
#![forbid(unsafe_code)] |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
pub trait Intent { |
| 79 |
|
| 80 |
fn token(self) -> &'static str; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 90 |
pub enum Bevel { |
| 91 |
|
| 92 |
Raised, |
| 93 |
|
| 94 |
|
| 95 |
Inset, |
| 96 |
} |
| 97 |
|
| 98 |
impl Bevel { |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
#[must_use] |
| 104 |
pub const fn edges(self) -> (Edge, Edge) { |
| 105 |
match self { |
| 106 |
Self::Raised => (Edge::Light, Edge::Dark), |
| 107 |
Self::Inset => (Edge::Dark, Edge::Light), |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
#[must_use] |
| 117 |
pub const fn pressed(self) -> Self { |
| 118 |
match self { |
| 119 |
Self::Raised => Self::Inset, |
| 120 |
Self::Inset => Self::Raised, |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 127 |
pub enum Edge { |
| 128 |
|
| 129 |
Light, |
| 130 |
|
| 131 |
Dark, |
| 132 |
} |
| 133 |
|
| 134 |
impl Intent for Edge { |
| 135 |
fn token(self) -> &'static str { |
| 136 |
match self { |
| 137 |
Self::Light => "bevel-light", |
| 138 |
Self::Dark => "bevel-dark", |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 157 |
#[non_exhaustive] |
| 158 |
pub enum Fill { |
| 159 |
|
| 160 |
Page, |
| 161 |
|
| 162 |
Raised, |
| 163 |
|
| 164 |
Overlay, |
| 165 |
|
| 166 |
Well, |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
Sunken, |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
impl Intent for Fill { |
| 193 |
fn token(self) -> &'static str { |
| 194 |
match self { |
| 195 |
Self::Page => "surface-page", |
| 196 |
Self::Raised => "surface-raised", |
| 197 |
Self::Overlay => "surface-overlay", |
| 198 |
Self::Well => "surface-well", |
| 199 |
Self::Sunken => "surface-sunken", |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 216 |
#[non_exhaustive] |
| 217 |
pub enum Depth { |
| 218 |
|
| 219 |
Flat, |
| 220 |
|
| 221 |
Raised, |
| 222 |
|
| 223 |
|
| 224 |
Well, |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
Sunken, |
| 236 |
} |
| 237 |
|
| 238 |
impl Depth { |
| 239 |
|
| 240 |
#[must_use] |
| 241 |
pub const fn bevel(self) -> Option<Bevel> { |
| 242 |
match self { |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
Self::Flat | Self::Sunken => None, |
| 247 |
Self::Raised => Some(Bevel::Raised), |
| 248 |
Self::Well => Some(Bevel::Inset), |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
#[must_use] |
| 257 |
pub const fn fill(self) -> Option<Fill> { |
| 258 |
match self { |
| 259 |
Self::Flat => None, |
| 260 |
Self::Raised => Some(Fill::Raised), |
| 261 |
Self::Well => Some(Fill::Well), |
| 262 |
Self::Sunken => Some(Fill::Sunken), |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
#[must_use] |
| 268 |
pub const fn pressed(self) -> Self { |
| 269 |
match self { |
| 270 |
Self::Raised => Self::Well, |
| 271 |
other => other, |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 289 |
pub enum Tone { |
| 290 |
|
| 291 |
Neutral, |
| 292 |
|
| 293 |
Info, |
| 294 |
|
| 295 |
Success, |
| 296 |
|
| 297 |
Warning, |
| 298 |
|
| 299 |
Danger, |
| 300 |
} |
| 301 |
|
| 302 |
impl Intent for Tone { |
| 303 |
fn token(self) -> &'static str { |
| 304 |
match self { |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
Self::Neutral => "content-muted", |
| 309 |
Self::Info => "info", |
| 310 |
Self::Success => "success", |
| 311 |
Self::Warning => "warning", |
| 312 |
Self::Danger => "danger", |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 332 |
pub enum Token { |
| 333 |
|
| 334 |
Badge, |
| 335 |
|
| 336 |
|
| 337 |
Chip { |
| 338 |
|
| 339 |
removable: bool, |
| 340 |
}, |
| 341 |
} |
| 342 |
|
| 343 |
impl Token { |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
#[must_use] |
| 349 |
pub const fn interactive(self) -> bool { |
| 350 |
matches!(self, Self::Chip { .. }) |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
#[must_use] |
| 358 |
pub const fn depth(self, latched: bool) -> Depth { |
| 359 |
match self { |
| 360 |
Self::Badge => Depth::Flat, |
| 361 |
Self::Chip { .. } if latched => Depth::Well, |
| 362 |
Self::Chip { .. } => Depth::Raised, |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 383 |
pub enum Notice { |
| 384 |
|
| 385 |
Toast, |
| 386 |
|
| 387 |
Banner, |
| 388 |
} |
| 389 |
|
| 390 |
impl Notice { |
| 391 |
|
| 392 |
#[must_use] |
| 393 |
pub const fn transient(self) -> bool { |
| 394 |
matches!(self, Self::Toast) |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
#[must_use] |
| 403 |
pub const fn fill(self) -> Fill { |
| 404 |
match self { |
| 405 |
Self::Toast => Fill::Overlay, |
| 406 |
Self::Banner => Fill::Raised, |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 419 |
pub enum RowPart { |
| 420 |
|
| 421 |
Primary, |
| 422 |
|
| 423 |
Secondary, |
| 424 |
|
| 425 |
Meta, |
| 426 |
|
| 427 |
Actions, |
| 428 |
} |
| 429 |
|
| 430 |
impl RowPart { |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
#[must_use] |
| 440 |
pub const fn revealed_on_hover(self) -> bool { |
| 441 |
matches!(self, Self::Actions) |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
#[must_use] |
| 446 |
pub const fn intent(self) -> &'static str { |
| 447 |
match self { |
| 448 |
Self::Primary => "content", |
| 449 |
Self::Secondary => "content-secondary", |
| 450 |
Self::Meta => "content-muted", |
| 451 |
|
| 452 |
Self::Actions => "content", |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 464 |
pub enum Heading { |
| 465 |
|
| 466 |
Page, |
| 467 |
|
| 468 |
Section, |
| 469 |
|
| 470 |
Subsection, |
| 471 |
} |
| 472 |
|
| 473 |
impl Heading { |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
#[must_use] |
| 480 |
pub const fn separated(self) -> bool { |
| 481 |
matches!(self, Self::Section) |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 491 |
pub enum Selector { |
| 492 |
|
| 493 |
Segmented, |
| 494 |
|
| 495 |
Toggle, |
| 496 |
|
| 497 |
Tabs, |
| 498 |
} |
| 499 |
|
| 500 |
impl Selector { |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
#[must_use] |
| 508 |
pub const fn chosen(self) -> Depth { |
| 509 |
match self { |
| 510 |
Self::Segmented | Self::Toggle => Depth::Well, |
| 511 |
Self::Tabs => Depth::Raised, |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
#[must_use] |
| 532 |
pub const fn unchosen(self) -> Depth { |
| 533 |
match self { |
| 534 |
Self::Tabs => Depth::Sunken, |
| 535 |
Self::Segmented | Self::Toggle => Depth::Raised, |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
#[must_use] |
| 546 |
pub const fn abutting(self) -> bool { |
| 547 |
matches!(self, Self::Segmented | Self::Tabs) |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 560 |
pub enum Readiness { |
| 561 |
|
| 562 |
Ready, |
| 563 |
|
| 564 |
Pending, |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 577 |
pub enum Region<'a> { |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
Band, |
| 583 |
|
| 584 |
Sidebar, |
| 585 |
|
| 586 |
Pane, |
| 587 |
|
| 588 |
Split, |
| 589 |
|
| 590 |
TabGroup, |
| 591 |
|
| 592 |
Modal, |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
Bespoke { |
| 612 |
|
| 613 |
name: &'a str, |
| 614 |
}, |
| 615 |
} |
| 616 |
|
| 617 |
impl Region<'_> { |
| 618 |
|
| 619 |
#[must_use] |
| 620 |
pub const fn depth(self) -> Depth { |
| 621 |
match self { |
| 622 |
Self::Band | Self::Sidebar | Self::Split | Self::TabGroup => Depth::Flat, |
| 623 |
|
| 624 |
Self::Pane => Depth::Well, |
| 625 |
Self::Modal => Depth::Raised, |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
Self::Bespoke { .. } => Depth::Flat, |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
#[must_use] |
| 640 |
pub const fn described(self) -> bool { |
| 641 |
!matches!(self, Self::Bespoke { .. }) |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 656 |
pub enum Arrangement { |
| 657 |
|
| 658 |
ListDetail { |
| 659 |
|
| 660 |
tabbed: bool, |
| 661 |
}, |
| 662 |
|
| 663 |
SidebarContent, |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 680 |
pub enum FieldKind { |
| 681 |
|
| 682 |
Text, |
| 683 |
|
| 684 |
|
| 685 |
Secret, |
| 686 |
|
| 687 |
Number, |
| 688 |
|
| 689 |
Textarea, |
| 690 |
|
| 691 |
Select, |
| 692 |
|
| 693 |
Checkbox, |
| 694 |
|
| 695 |
Hidden, |
| 696 |
} |
| 697 |
|
| 698 |
impl FieldKind { |
| 699 |
|
| 700 |
#[must_use] |
| 701 |
pub const fn visible(self) -> bool { |
| 702 |
!matches!(self, Self::Hidden) |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
#[must_use] |
| 707 |
pub const fn confidential(self) -> bool { |
| 708 |
matches!(self, Self::Secret) |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
#[must_use] |
| 717 |
pub const fn labels_itself(self) -> bool { |
| 718 |
matches!(self, Self::Checkbox) |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 727 |
pub struct Field<'a> { |
| 728 |
|
| 729 |
pub kind: FieldKind, |
| 730 |
|
| 731 |
pub name: &'a str, |
| 732 |
|
| 733 |
pub label: &'a str, |
| 734 |
|
| 735 |
pub hint: Option<&'a str>, |
| 736 |
|
| 737 |
pub error: Option<&'a str>, |
| 738 |
|
| 739 |
pub required: bool, |
| 740 |
|
| 741 |
pub extended: bool, |
| 742 |
} |
| 743 |
|
| 744 |
impl<'a> Field<'a> { |
| 745 |
|
| 746 |
#[must_use] |
| 747 |
pub const fn new(kind: FieldKind, name: &'a str, label: &'a str) -> Self { |
| 748 |
Self { |
| 749 |
kind, |
| 750 |
name, |
| 751 |
label, |
| 752 |
hint: None, |
| 753 |
error: None, |
| 754 |
required: false, |
| 755 |
extended: false, |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
#[must_use] |
| 768 |
pub const fn invalid(&self) -> bool { |
| 769 |
self.error.is_some() |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 779 |
pub enum Width { |
| 780 |
|
| 781 |
Content, |
| 782 |
|
| 783 |
Fixed, |
| 784 |
|
| 785 |
Fill, |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 796 |
pub enum Priority { |
| 797 |
|
| 798 |
Optional, |
| 799 |
|
| 800 |
Secondary, |
| 801 |
|
| 802 |
Essential, |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 811 |
pub struct Column<'a> { |
| 812 |
|
| 813 |
pub name: &'a str, |
| 814 |
|
| 815 |
pub width: Width, |
| 816 |
|
| 817 |
pub priority: Priority, |
| 818 |
} |
| 819 |
|
| 820 |
impl<'a> Column<'a> { |
| 821 |
|
| 822 |
#[must_use] |
| 823 |
pub const fn new(name: &'a str) -> Self { |
| 824 |
Self { |
| 825 |
name, |
| 826 |
width: Width::Fill, |
| 827 |
priority: Priority::Secondary, |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
#[must_use] |
| 836 |
pub const fn kept_at(&self, cutoff: Priority) -> bool { |
| 837 |
(self.priority as u8) >= (cutoff as u8) |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
#[cfg(test)] |
| 842 |
mod tests { |
| 843 |
use super::*; |
| 844 |
|
| 845 |
#[test] |
| 846 |
fn inset_is_raised_with_the_light_moved() { |
| 847 |
let (rl, rd) = Bevel::Raised.edges(); |
| 848 |
let (il, id) = Bevel::Inset.edges(); |
| 849 |
assert_eq!((rl, rd), (Edge::Light, Edge::Dark)); |
| 850 |
assert_eq!((il, id), (rd, rl)); |
| 851 |
} |
| 852 |
|
| 853 |
#[test] |
| 854 |
fn pressing_twice_is_a_no_op() { |
| 855 |
for b in [Bevel::Raised, Bevel::Inset] { |
| 856 |
assert_eq!(b.pressed().pressed(), b); |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
#[test] |
| 861 |
fn a_raised_region_is_never_filled_with_a_recessed_surface() { |
| 862 |
|
| 863 |
assert_eq!(Depth::Raised.fill(), Some(Fill::Raised)); |
| 864 |
assert_eq!(Depth::Raised.bevel(), Some(Bevel::Raised)); |
| 865 |
assert_eq!(Depth::Well.bevel(), Some(Bevel::Inset)); |
| 866 |
assert_ne!(Depth::Well.fill(), Depth::Raised.fill()); |
| 867 |
} |
| 868 |
|
| 869 |
#[test] |
| 870 |
fn flat_has_neither_edge_nor_fill() { |
| 871 |
assert_eq!(Depth::Flat.bevel(), None); |
| 872 |
assert_eq!(Depth::Flat.fill(), None); |
| 873 |
} |
| 874 |
|
| 875 |
#[test] |
| 876 |
fn sunken_is_recessed_by_colour_with_no_edge() { |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
assert_eq!(Depth::Sunken.fill(), Some(Fill::Sunken)); |
| 881 |
assert_eq!(Depth::Sunken.bevel(), None); |
| 882 |
} |
| 883 |
|
| 884 |
#[test] |
| 885 |
fn sunken_and_flat_are_different_claims() { |
| 886 |
|
| 887 |
|
| 888 |
assert_eq!(Depth::Flat.bevel(), Depth::Sunken.bevel()); |
| 889 |
assert_ne!(Depth::Flat.fill(), Depth::Sunken.fill()); |
| 890 |
} |
| 891 |
|
| 892 |
#[test] |
| 893 |
fn a_sunken_surface_is_not_a_well() { |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
assert_ne!(Fill::Sunken, Fill::Well); |
| 898 |
assert_eq!(Fill::Sunken.token(), "surface-sunken"); |
| 899 |
assert_eq!(Fill::Well.token(), "surface-well"); |
| 900 |
} |
| 901 |
|
| 902 |
#[test] |
| 903 |
fn every_selector_describes_both_of_its_states() { |
| 904 |
|
| 905 |
|
| 906 |
for s in [Selector::Tabs, Selector::Segmented, Selector::Toggle] { |
| 907 |
assert_ne!( |
| 908 |
s.chosen(), |
| 909 |
s.unchosen(), |
| 910 |
"{s:?} cannot tell picked from unpicked" |
| 911 |
); |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
#[test] |
| 916 |
fn only_a_tab_inverts_the_other_way() { |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
assert_eq!(Selector::Tabs.unchosen(), Depth::Sunken); |
| 922 |
assert_eq!(Selector::Tabs.chosen(), Depth::Raised); |
| 923 |
|
| 924 |
for s in [Selector::Segmented, Selector::Toggle] { |
| 925 |
assert_eq!(s.unchosen(), Depth::Raised); |
| 926 |
assert_eq!(s.chosen(), Depth::Well); |
| 927 |
|
| 928 |
assert_eq!(s.unchosen().pressed(), s.chosen()); |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
#[test] |
| 933 |
fn pressing_a_card_makes_a_well() { |
| 934 |
assert_eq!(Depth::Raised.pressed(), Depth::Well); |
| 935 |
assert_eq!( |
| 936 |
Depth::Raised.pressed().bevel(), |
| 937 |
Depth::Raised.bevel().map(Bevel::pressed) |
| 938 |
); |
| 939 |
|
| 940 |
assert_eq!(Depth::Flat.pressed(), Depth::Flat); |
| 941 |
assert_eq!(Depth::Well.pressed(), Depth::Well); |
| 942 |
} |
| 943 |
|
| 944 |
#[test] |
| 945 |
fn intents_name_makeover_tokens_and_nothing_else() { |
| 946 |
assert_eq!(Edge::Light.token(), "bevel-light"); |
| 947 |
assert_eq!(Edge::Dark.token(), "bevel-dark"); |
| 948 |
assert_eq!(Fill::Raised.token(), "surface-raised"); |
| 949 |
assert_eq!(Fill::Well.token(), "surface-well"); |
| 950 |
|
| 951 |
for t in [ |
| 952 |
Edge::Light.token(), |
| 953 |
Edge::Dark.token(), |
| 954 |
Tone::Danger.token(), |
| 955 |
Tone::Neutral.token(), |
| 956 |
] { |
| 957 |
assert!(!t.starts_with('#'), "{t} looks like a value"); |
| 958 |
assert!( |
| 959 |
!t.chars().next().unwrap().is_ascii_digit(), |
| 960 |
"{t} is a value" |
| 961 |
); |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
#[test] |
| 966 |
fn a_badge_cannot_be_pressed_and_a_chip_latches() { |
| 967 |
|
| 968 |
assert!(!Token::Badge.interactive()); |
| 969 |
assert!(Token::Chip { removable: false }.interactive()); |
| 970 |
assert!(Token::Chip { removable: true }.interactive()); |
| 971 |
|
| 972 |
|
| 973 |
assert_eq!(Token::Badge.depth(false), Depth::Flat); |
| 974 |
assert_eq!(Token::Badge.depth(true), Depth::Flat); |
| 975 |
|
| 976 |
|
| 977 |
let chip = Token::Chip { removable: false }; |
| 978 |
assert_eq!(chip.depth(false), Depth::Raised); |
| 979 |
assert_eq!(chip.depth(true), Depth::Raised.pressed()); |
| 980 |
} |
| 981 |
|
| 982 |
#[test] |
| 983 |
fn a_toast_and_a_banner_differ_in_more_than_placement() { |
| 984 |
assert!(Notice::Toast.transient()); |
| 985 |
assert!(!Notice::Banner.transient()); |
| 986 |
|
| 987 |
assert_eq!(Notice::Toast.fill(), Fill::Overlay); |
| 988 |
assert_eq!(Notice::Banner.fill(), Fill::Raised); |
| 989 |
} |
| 990 |
|
| 991 |
#[test] |
| 992 |
fn only_the_actions_part_hides_until_hovered() { |
| 993 |
for p in [RowPart::Primary, RowPart::Secondary, RowPart::Meta] { |
| 994 |
assert!(!p.revealed_on_hover(), "{p:?} should always be visible"); |
| 995 |
} |
| 996 |
assert!(RowPart::Actions.revealed_on_hover()); |
| 997 |
|
| 998 |
assert_eq!(RowPart::Primary.intent(), "content"); |
| 999 |
assert_eq!(RowPart::Secondary.intent(), "content-secondary"); |
| 1000 |
assert_eq!(RowPart::Meta.intent(), "content-muted"); |
| 1001 |
} |
| 1002 |
|
| 1003 |
#[test] |
| 1004 |
fn a_separator_is_what_tells_a_section_from_a_subsection() { |
| 1005 |
assert!(Heading::Section.separated()); |
| 1006 |
assert!(!Heading::Subsection.separated()); |
| 1007 |
assert!(!Heading::Page.separated()); |
| 1008 |
} |
| 1009 |
|
| 1010 |
#[test] |
| 1011 |
fn a_chosen_segment_is_held_in_and_a_chosen_tab_comes_forward() { |
| 1012 |
assert_eq!(Selector::Segmented.chosen(), Depth::Well); |
| 1013 |
assert_eq!(Selector::Toggle.chosen(), Depth::Well); |
| 1014 |
|
| 1015 |
|
| 1016 |
assert_eq!(Selector::Tabs.chosen(), Depth::Raised); |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
assert_eq!(Selector::Segmented.chosen(), Depth::Raised.pressed()); |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
assert!(Selector::Segmented.abutting()); |
| 1025 |
assert!(Selector::Tabs.abutting()); |
| 1026 |
assert!(!Selector::Toggle.abutting()); |
| 1027 |
} |
| 1028 |
|
| 1029 |
#[test] |
| 1030 |
fn a_pane_is_looked_into_and_a_band_is_not() { |
| 1031 |
assert_eq!(Region::Pane.depth(), Depth::Well); |
| 1032 |
assert_eq!(Region::Modal.depth(), Depth::Raised); |
| 1033 |
for r in [ |
| 1034 |
Region::Band, |
| 1035 |
Region::Sidebar, |
| 1036 |
Region::Split, |
| 1037 |
Region::TabGroup, |
| 1038 |
] { |
| 1039 |
assert_eq!(r.depth(), Depth::Flat, "{r:?} should carry no edge"); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
#[test] |
| 1044 |
fn exactly_one_region_is_opaque() { |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
for r in [ |
| 1049 |
Region::Band, |
| 1050 |
Region::Sidebar, |
| 1051 |
Region::Pane, |
| 1052 |
Region::Split, |
| 1053 |
Region::TabGroup, |
| 1054 |
Region::Modal, |
| 1055 |
] { |
| 1056 |
assert!(r.described(), "{r:?} should be describable"); |
| 1057 |
} |
| 1058 |
assert!(!Region::Bespoke { name: "day-plan" }.described()); |
| 1059 |
} |
| 1060 |
|
| 1061 |
#[test] |
| 1062 |
fn a_bespoke_region_inherits_its_depth_rather_than_choosing_one() { |
| 1063 |
|
| 1064 |
|
| 1065 |
assert_eq!(Region::Bespoke { name: "day-plan" }.depth(), Depth::Flat); |
| 1066 |
assert_eq!(Region::Bespoke { name: "kanban" }.depth(), Depth::Flat); |
| 1067 |
} |
| 1068 |
|
| 1069 |
#[test] |
| 1070 |
fn a_screen_with_a_bespoke_region_is_still_a_whole_screen() { |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
let day_plan = [ |
| 1075 |
Region::Band, |
| 1076 |
Region::Bespoke { name: "day-plan" }, |
| 1077 |
Region::Sidebar, |
| 1078 |
]; |
| 1079 |
assert_eq!(day_plan.iter().filter(|r| r.described()).count(), 2); |
| 1080 |
assert_eq!(day_plan.iter().filter(|r| !r.described()).count(), 1); |
| 1081 |
} |
| 1082 |
|
| 1083 |
#[test] |
| 1084 |
fn a_secret_field_is_marked_as_one_and_a_hidden_field_is_not_drawn() { |
| 1085 |
let secret = Field::new(FieldKind::Secret, "password", "Password"); |
| 1086 |
assert!(secret.kind.confidential()); |
| 1087 |
assert!(secret.kind.visible()); |
| 1088 |
|
| 1089 |
assert!(!FieldKind::Hidden.visible()); |
| 1090 |
|
| 1091 |
for k in [ |
| 1092 |
FieldKind::Text, |
| 1093 |
FieldKind::Number, |
| 1094 |
FieldKind::Textarea, |
| 1095 |
FieldKind::Select, |
| 1096 |
FieldKind::Checkbox, |
| 1097 |
FieldKind::Hidden, |
| 1098 |
] { |
| 1099 |
assert!(!k.confidential(), "{k:?} should not be confidential"); |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
assert!(FieldKind::Checkbox.labels_itself()); |
| 1104 |
assert!(!FieldKind::Text.labels_itself()); |
| 1105 |
} |
| 1106 |
|
| 1107 |
#[test] |
| 1108 |
fn a_field_reports_its_own_error_state() { |
| 1109 |
let mut f = Field::new(FieldKind::Text, "title", "Title"); |
| 1110 |
assert!(!f.invalid()); |
| 1111 |
f.error = Some("Required"); |
| 1112 |
assert!(f.invalid()); |
| 1113 |
} |
| 1114 |
|
| 1115 |
#[test] |
| 1116 |
fn columns_drop_by_priority_and_never_by_position() { |
| 1117 |
let cols = [ |
| 1118 |
Column { |
| 1119 |
name: "Title", |
| 1120 |
width: Width::Fill, |
| 1121 |
priority: Priority::Essential, |
| 1122 |
}, |
| 1123 |
Column { |
| 1124 |
name: "Due", |
| 1125 |
width: Width::Fixed, |
| 1126 |
priority: Priority::Secondary, |
| 1127 |
}, |
| 1128 |
Column { |
| 1129 |
name: "Estimate", |
| 1130 |
width: Width::Fixed, |
| 1131 |
priority: Priority::Optional, |
| 1132 |
}, |
| 1133 |
]; |
| 1134 |
|
| 1135 |
|
| 1136 |
assert_eq!( |
| 1137 |
cols.iter() |
| 1138 |
.filter(|c| c.kept_at(Priority::Optional)) |
| 1139 |
.count(), |
| 1140 |
3 |
| 1141 |
); |
| 1142 |
|
| 1143 |
let kept: Vec<_> = cols |
| 1144 |
.iter() |
| 1145 |
.filter(|c| c.kept_at(Priority::Secondary)) |
| 1146 |
.map(|c| c.name) |
| 1147 |
.collect(); |
| 1148 |
assert_eq!(kept, ["Title", "Due"]); |
| 1149 |
|
| 1150 |
let kept: Vec<_> = cols |
| 1151 |
.iter() |
| 1152 |
.filter(|c| c.kept_at(Priority::Essential)) |
| 1153 |
.map(|c| c.name) |
| 1154 |
.collect(); |
| 1155 |
assert_eq!(kept, ["Title"]); |
| 1156 |
} |
| 1157 |
|
| 1158 |
#[test] |
| 1159 |
fn inserting_a_column_does_not_move_what_gets_dropped() { |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
let before = [ |
| 1164 |
Column::new("Title"), |
| 1165 |
Column { |
| 1166 |
name: "Estimate", |
| 1167 |
width: Width::Fixed, |
| 1168 |
priority: Priority::Optional, |
| 1169 |
}, |
| 1170 |
]; |
| 1171 |
let after = [ |
| 1172 |
Column::new("Title"), |
| 1173 |
Column::new("Project"), |
| 1174 |
Column { |
| 1175 |
name: "Estimate", |
| 1176 |
width: Width::Fixed, |
| 1177 |
priority: Priority::Optional, |
| 1178 |
}, |
| 1179 |
]; |
| 1180 |
|
| 1181 |
fn dropped<'a>(cols: &[Column<'a>]) -> Vec<&'a str> { |
| 1182 |
cols.iter() |
| 1183 |
.filter(|c| !c.kept_at(Priority::Secondary)) |
| 1184 |
.map(|c| c.name) |
| 1185 |
.collect() |
| 1186 |
} |
| 1187 |
assert_eq!(dropped(&before), ["Estimate"]); |
| 1188 |
assert_eq!(dropped(&after), ["Estimate"]); |
| 1189 |
} |
| 1190 |
|
| 1191 |
#[test] |
| 1192 |
fn an_arrangement_carries_the_tab_group_as_a_modifier() { |
| 1193 |
|
| 1194 |
|
| 1195 |
let go = Arrangement::ListDetail { tabbed: true }; |
| 1196 |
let plain = Arrangement::ListDetail { tabbed: false }; |
| 1197 |
assert_ne!(go, plain); |
| 1198 |
assert_ne!(go, Arrangement::SidebarContent); |
| 1199 |
} |
| 1200 |
|
| 1201 |
#[test] |
| 1202 |
fn readiness_names_the_state_and_not_the_shimmer() { |
| 1203 |
|
| 1204 |
|
| 1205 |
assert_ne!(Readiness::Ready, Readiness::Pending); |
| 1206 |
} |
| 1207 |
} |
| 1208 |
|