Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/[email protected] #404

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"docs:assets": "cp -r docs/assets/** docs/dist/assets"
},
"dependencies": {
"@shopify/polaris-icons": "^9.1.1",
"@shopify/polaris-icons": "9.3.0",
"vite-svg-loader": "^5.1.0"
},
"devDependencies": {
"@csstools/postcss-global-data": "^2.1.1",
"@shopify/polaris-tokens": "^9.1.0",
"@shopify/polaris-tokens": "9.4.0",
"@shopify/postcss-plugin": "^5.0.2",
"@types/node": "^20.10.4",
"@vitejs/plugin-vue": "^5.0.5",
Expand Down
2 changes: 1 addition & 1 deletion polaris
Submodule polaris updated 91 files
+7 −0 .github/dependabot.yml
+10 −10 pnpm-lock.yaml
+21 −0 polaris-for-vscode/CHANGELOG.md
+2 −2 polaris-for-vscode/package.json
+14 −0 polaris-icons/CHANGELOG.md
+1 −0 polaris-icons/icons/AtmWithdrawalIcon.svg
+10 −0 polaris-icons/icons/AtmWithdrawalIcon.yml
+1 −0 polaris-icons/icons/CatalogIcon.svg
+13 −0 polaris-icons/icons/CatalogIcon.yml
+1 −0 polaris-icons/icons/FinanceFilledIcon.svg
+10 −0 polaris-icons/icons/FinanceFilledIcon.yml
+1 −0 polaris-icons/icons/FinanceIcon.svg
+10 −0 polaris-icons/icons/FinanceIcon.yml
+1 −0 polaris-icons/icons/InboundIcon.svg
+10 −0 polaris-icons/icons/InboundIcon.yml
+1 −0 polaris-icons/icons/MakePaymentIcon.svg
+10 −0 polaris-icons/icons/MakePaymentIcon.yml
+1 −0 polaris-icons/icons/OutboundIcon.svg
+10 −0 polaris-icons/icons/OutboundIcon.yml
+1 −0 polaris-icons/icons/PayoutDollarIcon.svg
+10 −0 polaris-icons/icons/PayoutDollarIcon.yml
+1 −0 polaris-icons/icons/PayoutEuroIcon.svg
+10 −0 polaris-icons/icons/PayoutEuroIcon.yml
+1 −0 polaris-icons/icons/PayoutIcon.svg
+10 −0 polaris-icons/icons/PayoutIcon.yml
+1 −0 polaris-icons/icons/PayoutPoundIcon.svg
+10 −0 polaris-icons/icons/PayoutPoundIcon.yml
+1 −0 polaris-icons/icons/PayoutRupeeIcon.svg
+10 −0 polaris-icons/icons/PayoutRupeeIcon.yml
+1 −0 polaris-icons/icons/PayoutYenIcon.svg
+10 −0 polaris-icons/icons/PayoutYenIcon.yml
+1 −0 polaris-icons/icons/ProductUnavailableIcon.svg
+10 −0 polaris-icons/icons/ProductUnavailableIcon.yml
+1,910 −0 polaris-icons/package-lock.json
+1 −1 polaris-icons/package.json
+24 −0 polaris-migrator/CHANGELOG.md
+4 −4 polaris-migrator/package.json
+0 −6 polaris-react/.storybook/addons/global-controls-panel/manager.jsx
+57 −0 polaris-react/CHANGELOG.md
+4 −4 polaris-react/locales/nl.json
+3 −3 polaris-react/package.json
+1 −10 polaris-react/src/components/AppProvider/AppProvider.tsx
+10 −4 polaris-react/src/components/ColorPicker/ColorPicker.tsx
+30 −3 polaris-react/src/components/ColorPicker/components/AlphaPicker/AlphaPicker.tsx
+34 −0 polaris-react/src/components/ColorPicker/components/AlphaPicker/tests/AlphaPicker.test.tsx
+31 −3 polaris-react/src/components/ColorPicker/components/HuePicker/HuePicker.tsx
+34 −0 polaris-react/src/components/ColorPicker/components/HuePicker/tests/HuePicker.test.tsx
+63 −16 polaris-react/src/components/ColorPicker/components/Slidable/Slidable.tsx
+130 −0 polaris-react/src/components/ColorPicker/components/Slidable/tests/Slidable.test.tsx
+40 −0 polaris-react/src/components/ColorPicker/tests/ColorPicker.test.tsx
+1 −1 polaris-react/src/components/Combobox/tests/Combobox.test.tsx
+18 −2 polaris-react/src/components/DropZone/DropZone.tsx
+41 −0 polaris-react/src/components/DropZone/tests/DropZone.test.tsx
+10 −2 polaris-react/src/components/EventListener/EventListener.tsx
+21 −0 polaris-react/src/components/EventListener/tests/EventListener.test.tsx
+0 −176 polaris-react/src/components/Frame/Frame.module.css
+8 −40 polaris-react/src/components/Frame/Frame.stories.tsx
+12 −90 polaris-react/src/components/Frame/Frame.tsx
+9 −3 polaris-react/src/components/KeypressListener/KeypressListener.tsx
+21 −0 polaris-react/src/components/KeypressListener/tests/KeypressListener.test.tsx
+0 −23 polaris-react/src/components/Navigation/Navigation.module.css
+3 −18 polaris-react/src/components/Navigation/Navigation.tsx
+48 −0 polaris-react/src/components/Navigation/tests/Navigation.test.tsx
+90 −44 polaris-react/src/components/Popover/Popover.tsx
+41 −3 polaris-react/src/components/Popover/components/PopoverOverlay/PopoverOverlay.tsx
+184 −1 polaris-react/src/components/Popover/components/PopoverOverlay/tests/PopoverOverlay.test.tsx
+120 −1 polaris-react/src/components/Popover/tests/Popover.test.tsx
+25 −11 polaris-react/src/components/PositionedOverlay/PositionedOverlay.tsx
+4 −1 polaris-react/src/components/PositionedOverlay/utilities/math.ts
+6 −6 polaris-react/src/components/Tabs/components/Item/Item.tsx
+17 −0 polaris-react/src/components/Tabs/components/Item/tests/Item.test.tsx
+3 −2 polaris-react/src/components/Tooltip/Tooltip.tsx
+2 −2 polaris-react/src/components/Tooltip/components/TooltipOverlay/TooltipOverlay.tsx
+50 −53 polaris-react/src/utilities/breakpoints.ts
+0 −1 polaris-react/src/utilities/features/types.ts
+16 −10 polaris-react/src/utilities/geometry.ts
+1 −0 polaris-react/src/utilities/is-element-in-viewport.ts
+9 −0 polaris-react/tests/setup/environment.ts
+15 −2 polaris-react/tests/setup/tests.ts
+18 −0 polaris-tokens/CHANGELOG.md
+1 −1 polaris-tokens/package.json
+35 −4 polaris-tokens/scripts/toMediaConditions.ts
+32 −32 polaris-tokens/src/colors.ts
+10 −30 polaris-tokens/src/themes/base/color.ts
+14 −22 polaris-tokens/src/themes/dark.ts
+47 −0 polaris.shopify.com/CHANGELOG.md
+1 −1 polaris.shopify.com/content/tools/polaris-migrator.mdx
+4 −4 polaris.shopify.com/package.json
+1 −1 polaris.shopify.com/src/components/CodesandboxButton/CodesandboxButton.tsx
+21 −0 stylelint-polaris/CHANGELOG.md
+2 −2 stylelint-polaris/package.json
15 changes: 9 additions & 6 deletions src/components/ColorPicker/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ div(
:color="colorHsb",
@change="handleAlphaChange",
)
EventListener(
event="resize",
:handler="handleResize",
)
</template>

<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import { computed, onMounted, onBeforeUnmount, reactive, ref } from 'vue';
import { debounce } from '@polaris/utilities/debounce';
import { clamp } from '@polaris/utilities/clamp';
import { classNames } from '@/utilities/css';
Expand All @@ -43,7 +39,6 @@ import {
hexToRgb,
rgbToHsb,
} from '@/utilities/color-transformers';
import { EventListener } from '@/components';
import { AlphaPicker, HuePicker, Slidable } from './components';
import styles from '@polaris/components/ColorPicker/ColorPicker.module.css';

Expand Down Expand Up @@ -88,6 +83,7 @@ const colorHsb = reactive<HSBAColor>({
});

const colorNode = ref<HTMLElement | null>(null);
const observer = ref<ResizeObserver | null>(null);
const huePickerRef = ref<HTMLElement | null>(null);

const draggerX = computed(() => clamp(colorHsb.saturation * pickerSize.width, 0, pickerSize.width));
Expand Down Expand Up @@ -162,6 +158,9 @@ onMounted(() => {
return;
}

observer.value = new ResizeObserver(handleResize);
observer.value.observe(colorNode.value);

pickerSize.width = colorNode.value.clientWidth;
pickerSize.height = colorNode.value.clientHeight;
});
Expand All @@ -175,6 +174,10 @@ const handleResize = debounce(() => {
pickerSize.height = colorNode.value.clientHeight;
}, RESIZE_DEBOUNCE_TIME_MS, { leading: true, trailing: true, maxWait: RESIZE_DEBOUNCE_TIME_MS });

onBeforeUnmount(() => {
observer.value?.disconnect();
})

const handleHueChange = (hue: number) => {
colorHsb.hue = hue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ div(
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, ref, onBeforeUnmount } from 'vue';
import type { HSBColor } from '@polaris/utilities/color-types';
import { hsbToRgb } from '@/utilities/color-transformers';
import { Slidable } from '../Slidable';
Expand All @@ -39,6 +39,7 @@ const emits = defineEmits<AlphaPickerEvents>();
const sliderHeight = ref(0);
const draggerHeight = ref(0);
const alphaPickerRef = ref<HTMLElement | null>(null);
const observer = ref<ResizeObserver | null>(null);

const draggerY = computed(() => {
return calculateDraggerY(props.alpha, sliderHeight.value, draggerHeight.value);
Expand All @@ -49,9 +50,19 @@ const background = computed(() => {
});

onMounted(() => {
if (!alphaPickerRef.value) { return; }

observer.value = new ResizeObserver(() => { setSliderHeight(); });

observer.value.observe(alphaPickerRef.value);

setSliderHeight();
});

onBeforeUnmount(() => {
observer.value?.disconnect();
});

const setSliderHeight = () => {
if (alphaPickerRef.value) {
sliderHeight.value = alphaPickerRef.value.clientHeight;
Expand Down
17 changes: 16 additions & 1 deletion src/components/ColorPicker/components/HuePicker/HuePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ div(
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, onBeforeUnmount, ref } from 'vue';
import { calculateDraggerY, hueForDraggerY } from '@polaris/components/ColorPicker/components/HuePicker/utilities';
import styles from '@polaris/components/ColorPicker/ColorPicker.module.css';
import { Slidable } from '../Slidable';
Expand All @@ -31,15 +31,30 @@ const emits = defineEmits<HuePickerEvents>();
const sliderHeight = ref(0);
const draggerHeight = ref(0);
const huePickerRef = ref<HTMLElement | null>(null);
const observer = ref<ResizeObserver | null>(null);

const draggerY = computed(() => {
return calculateDraggerY(props.hue, sliderHeight.value, draggerHeight.value);
});

onMounted(() => {
if (!huePickerRef.value) {
return;
}

observer.value = new ResizeObserver(() => {
setSliderHeight();
});

observer.value.observe(huePickerRef.value);

setSliderHeight();
});

onBeforeUnmount(() => {
observer.value?.disconnect();
});

const setSliderHeight = () => {
if (!huePickerRef.value) {
return;
Expand Down
32 changes: 30 additions & 2 deletions src/components/ColorPicker/components/Slidable/Slidable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ div(
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, ref, onBeforeUnmount } from 'vue';
import { isServer } from '@polaris/utilities/target';
import { EventListener } from '@/components';

Expand Down Expand Up @@ -77,6 +77,7 @@ if (!isServer) {

const nodeRef = ref<HTMLElement | null>(null);
const draggerNode = ref<HTMLElement | null>(null);
const observer = ref<ResizeObserver | null>(null);

const draggerPositioning = computed(() => ({
transform: `translate3d(${props.draggerX}px, ${props.draggerY}px, 0)`,
Expand All @@ -87,7 +88,26 @@ onMounted(() => {
return;
}

emits('dragger-height', draggerNode.value.clientWidth);
observer.value = new ResizeObserver(() => {
/**
* This is a workaround to enable event listeners to be
* re-attached when moving from one document to another
* when using a React portal across iframes.
* Using a resize observer works because when the clientWidth
* will go from 0 to the real width after the node
* gets rendered in its new place.
*/
// if (window !== draggerNode.value?.ownerDocument.defaultView) {
// (window as Window) = draggerNode.value?.ownerDocument.defaultView as Window;
// }
handleResize();
});

observer.value.observe(draggerNode.value);
});

onBeforeUnmount(() => {
observer.value?.disconnect();
});

const startDrag = (event: MouseEvent | TouchEvent) => {
Expand All @@ -98,6 +118,14 @@ const startDrag = (event: MouseEvent | TouchEvent) => {
isDragging.value = true;
};

const handleResize = () => {
if (!draggerNode.value) {
return;
}

emits('dragger-height', draggerNode.value.clientWidth);
}

const handleDragEnd = () => {
isDragging.value = false;
};
Expand Down
21 changes: 18 additions & 3 deletions src/components/DropZone/DropZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,16 @@ const currentInstance = getCurrentInstance();
const dropNodeRef = ref<HTMLDivElement | null>(null);
const inputRef = ref<HTMLInputElement | null>(null);
const dragTargets = ref<HTMLElement[]>([]);
const observer = ref<ResizeObserver | null>(null);

const dragging = ref(false);
const internalError = ref(false);
const { value: focused, setTrue: handleFocus, setFalse: handleBlur } = useToggle(false);
const size = ref('large');
const measuring = ref(true);

const customDocument = dropNodeRef.value?.ownerDocument || document;

const id = computed(() => props.id || uniqId);
const typeSuffix = computed(() => capitalize(props.type));
const allowMultipleKey = computed(() => createAllowMultipleKey(props.allowMultiple));
Expand Down Expand Up @@ -337,7 +340,7 @@ const handleDragLeave = (event: Event) => {
if (props.disabled) return;

dragTargets.value = dragTargets.value.filter((el) => {
const compareNode = props.dropOnPage ? document : dropNodeRef.value;
const compareNode = props.dropOnPage ? customDocument : dropNodeRef.value;

return el !== event.target && compareNode && compareNode.contains(el);
});
Expand Down Expand Up @@ -382,10 +385,20 @@ watch(
},
);

watch(
() => adjustSize,
() => {
if (!dropNodeRef.value) return;

observer.value = new ResizeObserver(adjustSize);
observer.value.observe(dropNodeRef.value);
},
)

onMounted(() => {
adjustSize();

const dropNode = props.dropOnPage ? document : dropNodeRef.value;
const dropNode = props.dropOnPage ? customDocument : dropNodeRef.value;

if (!dropNode) return;

Expand All @@ -397,7 +410,7 @@ onMounted(() => {
});

onBeforeUnmount(() => {
const dropNode = props.dropOnPage ? document : dropNodeRef.value;
const dropNode = props.dropOnPage ? customDocument : dropNodeRef.value;

if (!dropNode) return;

Expand All @@ -406,6 +419,8 @@ onBeforeUnmount(() => {
dropNode.removeEventListener('dragenter', handleDragEnter);
dropNode.removeEventListener('dragleave', handleDragLeave);
window.removeEventListener('resize', adjustSize);

observer.value?.disconnect();
});

const context = reactive<DropZoneContextType>({
Expand Down
5 changes: 5 additions & 0 deletions src/components/EventListener/EventListener.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type EventListenerProps = {
capture?: boolean;
handler(event: Event): void;
passive?: boolean;
customWindow?: Window | null;
}

const props = defineProps<EventListenerProps>();
Expand All @@ -38,13 +39,17 @@ watch(
);

function attachListener() {
const window = props.customWindow || globalThis.window;

window.addEventListener(props.event, props.handler, {
capture: props.capture,
passive: props.passive,
});
}

function detachListener() {
const window = props.customWindow || globalThis.window;

window.removeEventListener(props.event, props.handler, {
capture: props.capture,
});
Expand Down
46 changes: 45 additions & 1 deletion src/components/Popover/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ component(
)
slot(name="activator")
Portal(
v-if="activatorNode",
v-if="activatorNode && isDisplayed",
id-prefix="popover",
)
PopoverOverlay(
Expand All @@ -25,6 +25,7 @@ component(
<script setup lang="ts">
import {
onMounted,
onBeforeUnmount,
ref,
watch,
} from 'vue';
Expand Down Expand Up @@ -56,6 +57,8 @@ const slots = defineSlots<{

const id = useId();

const observer = ref<ResizeObserver | null>(null);
const isDisplayed = ref<boolean>(false);
const activatorNode = ref<HTMLElement | null>(null);
const activatorContainer = ref<HTMLElement | null>(null);
const overlayRef = ref<InstanceType<typeof PopoverOverlay> | HTMLElement | null>(null);
Expand Down Expand Up @@ -135,9 +138,25 @@ onMounted(() => {
activatorNode.value = activatorContainer.value.firstElementChild as HTMLElement;
}

if (!activatorNode.value) {
return;
}

observer.value = new ResizeObserver(() => {
setDisplayState();
});

observer.value.observe(activatorNode.value);

setDisplayState();

setAccessibilityAttributes();
});

onBeforeUnmount(() => {
observer.value?.disconnect();
});

function isInPortal(element: Element) {
let { parentElement } = element;

Expand All @@ -149,7 +168,32 @@ function isInPortal(element: Element) {
return true;
};

function setDisplayState() {
/**
* This is a workaround to prevent rendering the Popover when the content is moved into
* a React portal that hasn't been rendered. We don't want to render the Popover in this
* case because the auto-focus logic will break. We wait until the activatorContainer is
* displayed, which is when it has an offsetParent, or if the activatorContainer is the
* body, if it has a clientWidth bigger than 0.
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
*/
isDisplayed.value = Boolean(
activatorContainer.value
&& (activatorContainer.value.offsetParent !== null
|| (activatorContainer.value === activatorContainer.value.ownerDocument.body
&& activatorContainer.value.clientWidth > 0)),
);
}

defineExpose({
forceUpdatePosition,
close: (target = 'activator') => {
const source =
target === 'activator'
? PopoverCloseSource.EscapeKeypress
: PopoverCloseSource.FocusOut;

handleClose(source);
},
});
</script>
Loading