# getComponentKey

`getComponentKey` is a utility that returns a string that can be used as a key to refer to whether a component is collapsed on a particular content type. The utility finds the type ID of the content type where the component appears and the attribute value of the component's `nameAttribute`. If both values are found, a string in the form of `BSP.ContentEdit.widgetCollapsed.${typeId}.${componentName}` is returned. Otherwise, `null` is returned.

## Examples

Javascript

```
import getComponentKey from 'util/getComponentKey'

const key = getComponentKey(widget, 'data-internal-name')
```

## Parameters

| Name            | Type        | Description                                                                                                 |
| --------------- | ----------- | ----------------------------------------------------------------------------------------------------------- |
| `component`     | HTMLElement | The component whose key is being retrieved.                                                                 |
| `nameAttribute` | string      | The attribute on `component` whose value represents the name of `component` (e.g., a field or widget name). |

# storage

`storage` is a utility that abstracts the get and set `Storage` methods and adds a toggle method.

## Example

Javascript

```
import storage from 'util/storage'

storage.toggle(key, item.classList.toggle('is-expanded'))
```

## Static Methods

| Name                         | Params                                     | Description                                                                                                                                                                                                                                                                                     |
| ---------------------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `storage.get(key)`           | `key`: string                              | Retrieves the value of the key in `localStorage` or null if the key does not exist.                                                                                                                                                                                                             |
| `storage.set(key, value)`    | `key`: string, `value`: string             | Adds or updates the key's value in `localStorage`.                                                                                                                                                                                                                                              |
| `storage.toggle(key, force)` | `key`: string, `force`: boolean (optional) | With `force` omitted, toggles the key in `localStorage` (adds key with its value set to `1` if key is absent, removes key if already present). If `force` is true, sets the key's value to be `1` in `localStorage`. If `force` is false, removes the key from `localStorage`. Returns `force`. |
