Skip to main content Skip to navigation

Api Reference: **Component**

Component is the base class that provides basic functionality shared by all components in Hiker, including methods for manipulating component identification and classes.

callTraitsMethod(string $method): \Illuminate\Support\Collection

Parameters:

  • $method: string

Description:

Call a given method on all used traits.

Example:

ExampleComponent::make()->callTraitsMethod('exampleMethod');

classes($classes): self

Parameters:

  • $classes: string|array

Description:

Apply custom HTML classes to the component.

Example:

ExampleComponent::make()->classes('class1 class2');

componentId(): ?string

Description:

Get the identifier of the component.

Example:

$componentId = ExampleComponent::make()->componentId();

componentName(): string

Description:

Get the name of the component.

Example:

$componentName = ExampleComponent::make()->componentName();

component(): string

Description:

Get the Vue name of the component.

Example:

$componentVueName = ExampleComponent::make()->component();

conditionally(bool|callable $condition): ?static

Parameters:

  • $condition: bool|callable

Description:

Conditionally include the component based on a condition or a callable.

Example:

ExampleComponent::make()->conditionally(true);

css(array $styleDeclarations): static

Parameters:

  • $styleDeclarations: array

Description:

Set custom CSS declarations for the component.

Example:

ExampleComponent::make()->css(['color' => 'red', 'font-size' => '12px']);

customComponent(string $component): self

Parameters:

  • $component: string

Description:

Set a custom component.

Example:

ExampleComponent::make()->customComponent('custom-component');

forRoles(...$roles): ?static

Parameters:

  • $roles: string|array

Description:

Conditionally include the component only for given roles.

Example:

ExampleComponent::make()->forRoles('admin', 'editor');

forRole(string $role): ?static

Parameters:

  • $role: string

Description:

Conditionally include the component only for a given role.

Example:

ExampleComponent::make()->forRole('admin');

is(string $uri, string $id): bool

Parameters:

  • $uri: string
  • $id: string

Description:

Check if the component corresponds to the given description.

Example:

$isComponent = ExampleComponent::make()->is('uri', 'id');

make(...$arguments): static

Parameters:

  • $arguments: mixed

Description:

Create and return a new Component instance.

Example:

ExampleComponent::make('example')->method1('example');

uri(): string

Description:

Get the URI identifier of the component.

Example:

$componentUri = ExampleComponent::make()->uri();

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

Parameters:

  • $condition: bool - A boolean value that determines whether the callback should be executed.
  • $callback: callable - A callback function that will be executed if the condition is true.

Description:

This method allows you to conditionally execute a callback function to configure the component based on a boolean condition. If the condition is true, the callback will be executed and the component will be configured accordingly.

Example:

ExampleComponent::make('example')
    ->when($someCondition, function ($component) {
        $component->method1('example');
        $component->method2(['example', 'another example']);
    });