@digitransit-component/digitransit-component-favourite-editing-modal 7.0.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useEffect } from 'react';
1
+ import { useState, useRef, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { ReactSortable } from 'react-sortablejs';
@@ -8,6 +8,7 @@ import DialogModal from '@digitransit-component/digitransit-component-dialog-mod
8
8
  import { FlexColumn, Text, FlexRow } from '@hsl-fi/layout-primitives';
9
9
  import Icon from '@digitransit-component/digitransit-component-icon';
10
10
  import { createInstance } from 'i18next';
11
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
11
12
 
12
13
  function getDefaultExportFromCjs (x) {
13
14
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -6181,71 +6182,83 @@ function FavouriteListItem({
6181
6182
  });
6182
6183
  const iconId = getIconId(favourite.selectedIconId);
6183
6184
  const [name, address] = formatFavouritePlaceLabel(favourite.name, favourite.address);
6184
- return /*#__PURE__*/React.createElement("li", {
6185
- className: styles.item
6186
- }, /*#__PURE__*/React.createElement("div", {
6187
- className: styles.dragHandle
6188
- }, onMoveUp && /*#__PURE__*/React.createElement("button", {
6189
- type: "button",
6190
- className: styles.arrow,
6191
- "aria-label": t('up', {
6192
- lng: lang
6193
- }),
6194
- onClick: onMoveUp
6195
- }, "\u2191"), onMoveDown && /*#__PURE__*/React.createElement("button", {
6196
- type: "button",
6197
- className: styles.arrow,
6198
- "aria-label": t('down', {
6199
- lng: lang
6200
- }),
6201
- onClick: onMoveDown
6202
- }, "\u2193"), /*#__PURE__*/React.createElement("span", {
6203
- className: styles.ellipsis
6204
- }, /*#__PURE__*/React.createElement(Icon, {
6205
- img: "ellipsis",
6206
- color: "currentColor"
6207
- })), /*#__PURE__*/React.createElement("span", {
6208
- className: styles.placeIcon
6209
- }, /*#__PURE__*/React.createElement(Icon, {
6210
- img: iconId,
6211
- color: "currentColor"
6212
- }))), /*#__PURE__*/React.createElement(FlexColumn, {
6213
- className: styles.text
6214
- }, /*#__PURE__*/React.createElement(Text, {
6215
- variant: "text-xs-bold",
6216
- as: "p",
6217
- className: styles.name
6218
- }, name), /*#__PURE__*/React.createElement(Text, {
6219
- variant: "text-xs",
6220
- as: "p",
6221
- color: "weak",
6222
- className: styles.address
6223
- }, address)), /*#__PURE__*/React.createElement(FlexRow, {
6224
- alignItems: "center",
6225
- flexShrink: 0
6226
- }, /*#__PURE__*/React.createElement("button", {
6227
- type: "button",
6228
- className: styles.actionButton,
6229
- "aria-label": t('edit-place-name', {
6230
- lng: lang,
6231
- favourite
6232
- }),
6233
- onClick: onEdit
6234
- }, /*#__PURE__*/React.createElement(Icon, {
6235
- img: "edit",
6236
- color: "currentColor"
6237
- })), /*#__PURE__*/React.createElement("button", {
6238
- type: "button",
6239
- className: styles.actionButton,
6240
- "aria-label": t('delete-place-name', {
6241
- lng: lang,
6242
- favourite
6243
- }),
6244
- onClick: onDelete
6245
- }, /*#__PURE__*/React.createElement(Icon, {
6246
- img: "trash",
6247
- color: "currentColor"
6248
- }))));
6185
+ return /*#__PURE__*/jsxs("li", {
6186
+ className: styles.item,
6187
+ children: [/*#__PURE__*/jsxs("div", {
6188
+ className: styles.dragHandle,
6189
+ children: [onMoveUp && /*#__PURE__*/jsx("button", {
6190
+ type: "button",
6191
+ className: styles.arrow,
6192
+ "aria-label": t('up', {
6193
+ lng: lang
6194
+ }),
6195
+ onClick: onMoveUp,
6196
+ children: "\u2191"
6197
+ }), onMoveDown && /*#__PURE__*/jsx("button", {
6198
+ type: "button",
6199
+ className: styles.arrow,
6200
+ "aria-label": t('down', {
6201
+ lng: lang
6202
+ }),
6203
+ onClick: onMoveDown,
6204
+ children: "\u2193"
6205
+ }), /*#__PURE__*/jsx("span", {
6206
+ className: styles.ellipsis,
6207
+ children: /*#__PURE__*/jsx(Icon, {
6208
+ img: "ellipsis",
6209
+ color: "currentColor"
6210
+ })
6211
+ }), /*#__PURE__*/jsx("span", {
6212
+ className: styles.placeIcon,
6213
+ children: /*#__PURE__*/jsx(Icon, {
6214
+ img: iconId,
6215
+ color: "currentColor"
6216
+ })
6217
+ })]
6218
+ }), /*#__PURE__*/jsxs(FlexColumn, {
6219
+ className: styles.text,
6220
+ children: [/*#__PURE__*/jsx(Text, {
6221
+ variant: "text-xs-bold",
6222
+ as: "p",
6223
+ className: styles.name,
6224
+ children: name
6225
+ }), /*#__PURE__*/jsx(Text, {
6226
+ variant: "text-xs",
6227
+ as: "p",
6228
+ color: "weak",
6229
+ className: styles.address,
6230
+ children: address
6231
+ })]
6232
+ }), /*#__PURE__*/jsxs(FlexRow, {
6233
+ alignItems: "center",
6234
+ flexShrink: 0,
6235
+ children: [/*#__PURE__*/jsx("button", {
6236
+ type: "button",
6237
+ className: styles.actionButton,
6238
+ "aria-label": t('edit-place-name', {
6239
+ lng: lang,
6240
+ favourite
6241
+ }),
6242
+ onClick: onEdit,
6243
+ children: /*#__PURE__*/jsx(Icon, {
6244
+ img: "edit",
6245
+ color: "currentColor"
6246
+ })
6247
+ }), /*#__PURE__*/jsx("button", {
6248
+ type: "button",
6249
+ className: styles.actionButton,
6250
+ "aria-label": t('delete-place-name', {
6251
+ lng: lang,
6252
+ favourite
6253
+ }),
6254
+ onClick: onDelete,
6255
+ children: /*#__PURE__*/jsx(Icon, {
6256
+ img: "trash",
6257
+ color: "currentColor"
6258
+ })
6259
+ })]
6260
+ })]
6261
+ });
6249
6262
  }
6250
6263
  process.env.NODE_ENV !== "production" ? FavouriteListItem.propTypes = {
6251
6264
  favourite: PropTypes.shape({
@@ -6260,24 +6273,6 @@ process.env.NODE_ENV !== "production" ? FavouriteListItem.propTypes = {
6260
6273
  onMoveDown: PropTypes.func
6261
6274
  } : void 0;
6262
6275
 
6263
- /**
6264
- * A dialog for reordering, editing and deleting favourite places, built on
6265
- * the HSL design system's Modal. Colors, typography and the mobile/desktop
6266
- * layout are handled by the design system, so the dialog follows the active
6267
- * deployment's theme.
6268
- *
6269
- * @example
6270
- * <FavouriteEditingModal
6271
- * isModalOpen={modalOpen}
6272
- * handleClose={handleClose}
6273
- * favourites={favourites}
6274
- * updateFavourites={onUpdateFavourites}
6275
- * deleteFavourite={onDeleteFavourite}
6276
- * onEditSelected={onEditSelected}
6277
- * isLoading={false}
6278
- * lang="fi"
6279
- * />
6280
- */
6281
6276
  function FavouriteEditingModal({
6282
6277
  isModalOpen,
6283
6278
  handleClose,
@@ -6331,65 +6326,71 @@ function FavouriteEditingModal({
6331
6326
  }
6332
6327
  };
6333
6328
  const closeDeleteDialog = () => setSelectedFavourite(null);
6334
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DialogModal, {
6335
- headerText: t('delete-place-header', {
6336
- lng: lang
6337
- }),
6338
- handleClose: () => {
6339
- closeDeleteDialog();
6340
- handleClose();
6341
- },
6342
- isModalOpen: selectedFavourite !== null,
6343
- dialogContent: selectedFavourite ? `${selectedFavourite.name}: ${selectedFavourite.address}` : '',
6344
- primaryButtonText: t('delete', {
6345
- lng: lang
6346
- }),
6347
- primaryButtonOnClick: () => {
6348
- deleteFavourite(selectedFavourite);
6349
- closeDeleteDialog();
6350
- },
6351
- secondaryButtonText: t('cancel', {
6352
- lng: lang
6353
- }),
6354
- secondaryButtonOnClick: closeDeleteDialog,
6355
- lang: lang
6356
- }), /*#__PURE__*/React.createElement(Modal, {
6357
- open: isModalOpen && selectedFavourite === null,
6358
- onOpenChange: open => {
6359
- if (!open) {
6360
- closeModal();
6361
- }
6362
- }
6363
- }, /*#__PURE__*/React.createElement(ModalContent, {
6364
- lang: lang,
6365
- title: t('edit-places', {
6366
- lng: lang
6367
- }),
6368
- className: styles.modalContent,
6369
- "aria-describedby": undefined
6370
- }, /*#__PURE__*/React.createElement("div", {
6371
- className: styles.listContainer
6372
- }, /*#__PURE__*/React.createElement(ReactSortable, {
6373
- className: styles.list,
6374
- tag: "ul",
6375
- list: items,
6376
- setList: setList,
6377
- animation: 200,
6378
- handle: `.${DRAG_HANDLE_CLASS}`,
6379
- forceFallback: true,
6380
- ghostClass: styles.ghost,
6381
- fallbackClass: styles.fallback
6382
- }, items.map((favourite, index) => /*#__PURE__*/React.createElement(FavouriteListItem, {
6383
- key: favourite.favouriteId,
6384
- favourite: favourite,
6385
- lang: lang,
6386
- onMoveUp: index > 0 ? () => move(index, -1) : null,
6387
- onMoveDown: index < items.length - 1 ? () => move(index, 1) : null,
6388
- onEdit: () => onEditSelected(favourite),
6389
- onDelete: () => setSelectedFavourite(favourite)
6390
- }))), isLoading && /*#__PURE__*/React.createElement("div", {
6391
- className: styles.overlay
6392
- }, /*#__PURE__*/React.createElement(Spinner, null))))));
6329
+ return /*#__PURE__*/jsxs(Fragment, {
6330
+ children: [/*#__PURE__*/jsx(DialogModal, {
6331
+ headerText: t('delete-place-header', {
6332
+ lng: lang
6333
+ }),
6334
+ handleClose: () => {
6335
+ closeDeleteDialog();
6336
+ handleClose();
6337
+ },
6338
+ isModalOpen: selectedFavourite !== null,
6339
+ dialogContent: selectedFavourite ? `${selectedFavourite.name}: ${selectedFavourite.address}` : '',
6340
+ primaryButtonText: t('delete', {
6341
+ lng: lang
6342
+ }),
6343
+ primaryButtonOnClick: () => {
6344
+ deleteFavourite(selectedFavourite);
6345
+ closeDeleteDialog();
6346
+ },
6347
+ secondaryButtonText: t('cancel', {
6348
+ lng: lang
6349
+ }),
6350
+ secondaryButtonOnClick: closeDeleteDialog,
6351
+ lang: lang
6352
+ }), /*#__PURE__*/jsx(Modal, {
6353
+ open: isModalOpen && selectedFavourite === null,
6354
+ onOpenChange: open => {
6355
+ if (!open) {
6356
+ closeModal();
6357
+ }
6358
+ },
6359
+ children: /*#__PURE__*/jsx(ModalContent, {
6360
+ lang: lang,
6361
+ title: t('edit-places', {
6362
+ lng: lang
6363
+ }),
6364
+ className: styles.modalContent,
6365
+ "aria-describedby": undefined,
6366
+ children: /*#__PURE__*/jsxs("div", {
6367
+ className: styles.listContainer,
6368
+ children: [/*#__PURE__*/jsx(ReactSortable, {
6369
+ className: styles.list,
6370
+ tag: "ul",
6371
+ list: items,
6372
+ setList: setList,
6373
+ animation: 200,
6374
+ handle: `.${DRAG_HANDLE_CLASS}`,
6375
+ forceFallback: true,
6376
+ ghostClass: styles.ghost,
6377
+ fallbackClass: styles.fallback,
6378
+ children: items.map((favourite, index) => /*#__PURE__*/jsx(FavouriteListItem, {
6379
+ favourite: favourite,
6380
+ lang: lang,
6381
+ onMoveUp: index > 0 ? () => move(index, -1) : null,
6382
+ onMoveDown: index < items.length - 1 ? () => move(index, 1) : null,
6383
+ onEdit: () => onEditSelected(favourite),
6384
+ onDelete: () => setSelectedFavourite(favourite)
6385
+ }, favourite.favouriteId))
6386
+ }), isLoading && /*#__PURE__*/jsx("div", {
6387
+ className: styles.overlay,
6388
+ children: /*#__PURE__*/jsx(Spinner, {})
6389
+ })]
6390
+ })
6391
+ })
6392
+ })]
6393
+ });
6393
6394
  }
6394
6395
  process.env.NODE_ENV !== "production" ? FavouriteEditingModal.propTypes = {
6395
6396
  /** Required. Whether the dialog is open.