diff --git a/src/Components/Alert.php b/src/Components/Alert.php index dadd2f5..32d35a6 100644 --- a/src/Components/Alert.php +++ b/src/Components/Alert.php @@ -1,15 +1,31 @@ elevation < 0 || $this->elevation > 24) { + throw new InvalidArgumentException( + "Elevation must be between 0 and 24, got {$this->elevation}. ". + 'See Material Design elevation specification: https://m2.material.io/design/environment/elevation.html' + ); + } + if ($variant) { $this->variant = Variant::fromString($variant); } @@ -53,8 +86,21 @@ public function render() return 'mbv::alert'; } + /** + * Preprocess component attributes to apply styling and classes. + * + * Applies appropriate styling based on variant (standard, filled, outlined), + * adds Material Design elevation classes, and sets typography. + * + * @param ComponentAttributeBag $attributes Component attributes + * @return ComponentAttributeBag Processed attributes with classes and styles + */ public function attributesPreprocess(ComponentAttributeBag $attributes): ComponentAttributeBag { + $attributes = $attributes->class([ + "mdc-elevation--z{$this->elevation}" => $this->elevation > 0 && $this->elevation <= 24, + ]); + if ($this->variant === Variant::FILLED) { return $attributes->style([ "background-color: {$this->cssColor}", @@ -78,6 +124,14 @@ public function attributesPreprocess(ComponentAttributeBag $attributes): Compone ])->class('mdc-typography--body1'); } + /** + * Get the icon to display in the alert. + * + * Returns custom icon if provided, otherwise returns default icon + * based on severity level with 'outlined' variant. + * + * @return string|array Icon name as string or [name, variant] array + */ public function getIcon(): string|array { return $this->icon ?? match ($this->severity) {