Skip to content

Commit

Permalink
fix(SfScrollable): floating disabled state, refactor (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon-dziewonski committed Jul 25, 2023
1 parent 7801e66 commit 6bf2b3f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .changeset/short-lions-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@storefront-ui/react': patch
'@storefront-ui/vue': patch
---

Unify code between vue and react, when buttons are disabled in floating button position mode they should be hidden
21 changes: 1 addition & 20 deletions apps/docs/components/components/scrollable.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ This component is shipped in our NPM package, but its API might change based on
::: read-more

<!-- react -->

Learn more about `useScrollable` hook in the [Hooks > useScrollable docs](/react/hooks/useScrollable.html).

<!-- end react -->
<!-- vue -->

Learn more about `useScrollable` composable in the [Composables > useScrollable docs](/vue/hooks/useScrollable.html).

<!-- end vue -->

:::
Expand All @@ -36,14 +32,10 @@ Can be setup that will be without scrollbar
<Showcase showcase-name="Scrollable/HideScrollbar" style="min-height:240px">

<!-- vue -->

<<<../../preview/nuxt/pages/showcases/Scrollable/HideScrollbar.vue

<!-- end vue -->
<!-- react -->

<<<../../preview/next/pages/showcases/Scrollable/HideScrollbar.tsx#source

<!-- end react -->

</Showcase>
Expand All @@ -55,14 +47,10 @@ Can be setup that will be without scrollbar
<Showcase showcase-name="Scrollable/SnapCenter" style="min-height:260px">

<!-- vue -->

<<<../../preview/nuxt/pages/showcases/Scrollable/SnapCenter.vue

<!-- end vue -->
<!-- react -->

<<<../../preview/next/pages/showcases/Scrollable/SnapCenter.tsx#source

<!-- end react -->

</Showcase>
Expand All @@ -74,14 +62,10 @@ By default `SfScrollable` scroll by one page of items, but can be modified that
<Showcase showcase-name="Scrollable/ScrollByOneItem" style="min-height:260px">

<!-- vue -->

<<<../../preview/nuxt/pages/showcases/Scrollable/ScrollByOneItem.vue

<!-- end vue -->
<!-- react -->

<<<../../preview/next/pages/showcases/Scrollable/ScrollByOneItem.tsx#source

<!-- end react -->

</Showcase>
Expand Down Expand Up @@ -157,14 +141,11 @@ The previous and next buttons have `aria-label` attributes (`buttonPrevAriaLabel
<SourceCode>

<!-- vue -->

<<<../../../packages/sfui/frameworks/vue/components/SfScrollable/SfScrollable.vue

<!-- end vue -->
<!-- react -->

<<< ../../../packages/sfui/frameworks/react/components/SfScrollable/SfScrollable.tsx

<!-- end react -->

</SourceCode>
::::::
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
slotPrefix: <SfIconChevronLeft />,
ariaLabel: buttonPrevAriaLabel,
className: classNames(
'hidden md:block !ring-neutral-500 !text-neutral-500 disabled:!ring-disabled-300 disabled:!text-disabled-500',
classNameButton,
isFloating ? 'disabled:hidden' : 'disabled:!ring-disabled-300 disabled:!text-disabled-500',
),
})}
/>
Expand All @@ -114,8 +114,8 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
slotPrefix: <SfIconChevronRight />,
ariaLabel: buttonNextAriaLabel,
className: classNames(
'hidden md:block !ring-neutral-500 !text-neutral-500 disabled:!ring-disabled-300 disabled:!text-disabled-500',
classNameButton,
isFloating ? 'disabled:hidden' : 'disabled:!ring-disabled-300 disabled:!text-disabled-500',
),
})}
/>
Expand All @@ -131,7 +131,7 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
>
{buttonsPlacement !== SfScrollableButtonsPlacement.none && (
<PreviousButton
classNameButton={classNames('!rounded-full bg-white', {
classNameButton={classNames('!rounded-full bg-white hidden md:block !ring-neutral-500 !text-neutral-500', {
'mr-4': isBlock && isHorizontal,
'mb-4 rotate-90': isBlock && !isHorizontal,
'absolute left-4 z-10': isFloating && isHorizontal,
Expand All @@ -152,7 +152,7 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
</Tag>
{buttonsPlacement !== SfScrollableButtonsPlacement.none && (
<NextButton
classNameButton={classNames('!rounded-full bg-white', {
classNameButton={classNames('!rounded-full bg-white hidden md:block !ring-neutral-500 !text-neutral-500', {
'ml-4': isBlock && isHorizontal,
'mt-4 rotate-90': isBlock && !isHorizontal,
'absolute right-4 z-10': isFloating && isHorizontal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ const { containerRef, state, getNextButtonProps, getPrevButtonProps } = useScrol
})),
);
const changeDisabledClass = (isDisabled: boolean) =>
isDisabled ? '!ring-disabled-300 !text-disabled-500' : '!ring-neutral-500 !text-neutral-500';
const isHorizontal = computed(() => props.direction === SfScrollableDirection.horizontal);
const isFloating = computed(() => props.buttonsPlacement === SfScrollableButtonsPlacement.floating);
const isBlock = computed(() => props.buttonsPlacement === SfScrollableButtonsPlacement.block);
</script>

<template>
Expand All @@ -112,14 +112,17 @@ const isHorizontal = computed(() => props.direction === SfScrollableDirection.ho
size="lg"
square
:class="[
'!rounded-full bg-white hidden md:block',
buttonsPlacement === SfScrollableButtonsPlacement.block && (isHorizontal ? 'mr-4' : 'mb-4 rotate-90'),
buttonsPlacement === SfScrollableButtonsPlacement.floating && (isHorizontal ? 'left-4' : 'top-4 rotate-90'),
{ 'absolute z-10': buttonsPlacement === SfScrollableButtonsPlacement.floating },
changeDisabledClass(typeof prevDisabled === 'boolean' ? prevDisabled : getPrevButtonProps.disabled),
'!rounded-full bg-white hidden md:block !ring-neutral-500 !text-neutral-500',
{
'mr-4': isBlock && isHorizontal,
'mb-4 rotate-90': isBlock && !isHorizontal,
'absolute left-4 z-10': isFloating && isHorizontal,
'absolute top-4 rotate-90 z-10': isFloating && !isHorizontal,
},
isFloating ? 'disabled:hidden' : 'disabled:!ring-disabled-300 disabled:!text-disabled-500',
]"
v-bind="getPrevButtonProps"
:disabled="prevDisabled"
:disabled="prevDisabled || getPrevButtonProps.disabled"
:aria-label="buttonPrevAriaLabel"
>
<SfIconChevronLeft />
Expand Down Expand Up @@ -151,14 +154,17 @@ const isHorizontal = computed(() => props.direction === SfScrollableDirection.ho
size="lg"
square
:class="[
'!rounded-full bg-white hidden md:block',
buttonsPlacement === SfScrollableButtonsPlacement.block && (isHorizontal ? 'ml-4' : 'mt-4 rotate-90'),
buttonsPlacement === SfScrollableButtonsPlacement.floating && (isHorizontal ? 'right-4' : 'bottom-4 rotate-90'),
{ 'absolute z-10': buttonsPlacement === SfScrollableButtonsPlacement.floating },
changeDisabledClass(typeof nextDisabled === 'boolean' ? nextDisabled : getNextButtonProps.disabled),
'!rounded-full bg-white hidden md:block !ring-neutral-500 !text-neutral-500',
{
'ml-4': isBlock && isHorizontal,
'mt-4 rotate-90': isBlock && !isHorizontal,
'absolute right-4 z-10': isFloating && isHorizontal,
'absolute bottom-4 rotate-90 z-10': isFloating && !isHorizontal,
},
isFloating ? 'disabled:hidden' : 'disabled:!ring-disabled-300 disabled:!text-disabled-500',
]"
v-bind="getNextButtonProps"
:disabled="nextDisabled"
:disabled="nextDisabled || getNextButtonProps.disabled"
:aria-label="buttonNextAriaLabel"
>
<SfIconChevronRight />
Expand Down

0 comments on commit 6bf2b3f

Please sign in to comment.