{/* prettier-ignore */}
{/*
Copyright 2023 Comcast Cable Communications Management, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
\*/}

import { Meta } from '@storybook/blocks';
import * as withEditItemsStories from './withEditItems.stories';

<Meta of={withEditItemsStories} />

# withEditItems

The `withEditItems` mixin can be wrapped around any component that is or extends a FocusManager to enable rearranging the position of items with an animation

## Source

https://github.com/rdkcentral/Lightning-UI-Components/blob/develop/packages/@lightningjs/ui-components/src/mixins/withEditItems/index.js

## Usage

```js
class Basic extends lng.Component {
  static _template() {
    return {
      TileRow: {
        type: withEditItems(Row),
        items: [
            {
                title: 'item-1'
            },{
                title: 'item-2'
            }, {
                ...
            }... ]
      }
    };
  }

  //Some trigger, in this case a keypress handler to trigger the Tile Row's ability to swap an items position
  _handleEnter() {
      this.tag('TileRow').toggleEdit();
  }
}
```

## API

### Methods

#### toggleEdit(): void

Called from parent of extended Row/Column to trigger the flow of editing the order of items in the item array

#### \_swapItemArrayPos(): void

Called each time on the update of the selectedIndex value when both editMode is true and isEditing is set to true on Enter press.
returns the original items array with an updated order, swaping the positions of the selecte item and the next or previous item depending on the direction of the swap
