Skip to content

Commit

Permalink
Allow an ID to be passed in as a string
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 21, 2024
1 parent 162eaa3 commit 8c06ddd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 2.12.0 - Unreleased

### Added

- Added the ability to assign an ID to a component by passing a string as the third argument to the `sprig()` function.

### Deprecated

- Deprecated `sprig.getIsBoosted`, `sprig.getIsError`, `sprig.getIsHistoryRestoreRequest`, `sprig.getIsInclude`, `sprig.getIsRequest`, `sprig.getIsSuccess`. Use `sprig.isBoosted`, `sprig.isError`, `sprig.isHistoryRestoreRequest`, `sprig.isInclude`, `sprig.isRequest`, `sprig.isSuccess` instead.
Expand Down
7 changes: 6 additions & 1 deletion src/services/ComponentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function setConfig(array $options = []): void
/**
* Creates a new component.
*/
public function create(string $value, array $variables = [], array $attributes = []): Markup
public function create(string $value, array $variables = [], array|string $attributes = []): Markup
{
$this->componentName = $value;
$values = [];
Expand All @@ -219,6 +219,11 @@ public function create(string $value, array $variables = [], array $attributes =
Sprig::$core->requests->getVariables()
);

// Allow an ID to be passed in as a string
if (is_string($attributes)) {
$attributes = ['id' => $attributes];
}

$event = new ComponentEvent([
'value' => $value,
'variables' => $mergedVariables,
Expand Down

0 comments on commit 8c06ddd

Please sign in to comment.