Skip to main content Skip to navigation

Components: Base component

How to use

This is the base class that all other Hiker components extend. You should not use it directly, but all the other components inherit these methods.

Available methods

make(...$arguments): Component

Create a component instance. Passes given arguments to the component's constructor.

Component::make($args)

setComponentId(?string $id): static

Set the component's identifier.

Component::make()
    ->setComponentId('some-id')

componentId(): ?string

Get the component's identifier.

Component::make()->componentId()

customComponent(string $component): static

Set a custom vue component name for this component.

Component::make()->customComponent('my-custom-vue-component')

componentName(): string

Get the vue component's name.

Component::make()->componentName()

classes(string|array $classes): static

Apply some custom html classes to this component.

Component::make()->classes(['custom-class', 'another-custom-class'])

css(array $css): static

Set custom css declarations for the component.

Component::make()->css(['backgroundColor' => '#7959EF'])

hasTrait(string $trait): bool

Check if the component uses a specific trait.

Component::make()->hasTrait(HasIcon::class)

conditionally(bool|callable $condition): ?static

Conditionally include the component.

Component::make()->conditionally(true)
// or
Component::make()
    ->conditionally(function (Component $instance) {
        return true;
    })

when(bool $condition, callable $callback): static

Conditionally execute the callback to configure the component.

Component::make()
    ->when(true, function (Component $instance) {
        // Configure $instance
    })