-
Notifications
You must be signed in to change notification settings - Fork 353
feat(color-picker): add placement prop
#4088
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
base: dev
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { test, expect } from '@playwright/test' | ||
|
|
||
|
|
||
| test('placement', async ({ page }) => { | ||
| // 测试 | ||
| page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
| await page.locator('#placement').selectOption('top') | ||
| await expect(page.locator('.t-color-picker__panel')).toHaveCSS('top', '0px') | ||
| await page.locator('#placement').selectOption('bottom') | ||
| await expect(page.locator('.t-color-picker__panel')).toHaveCSS('top', 'auto') | ||
|
Comment on lines
+4
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check how other color-picker e2e tests are structured (page.goto, selectors)
find examples/sites/demos/pc/app/color-picker -name "*.spec.ts" -type f | head -10Repository: opentiny/tiny-vue Length of output: 655 🏁 Script executed: #!/bin/bash
# Look at a few other spec files for structure
fd 'spec.ts' examples/sites/demos/pc/app/color-picker --exec head -15 {}Repository: opentiny/tiny-vue Length of output: 5827 🏁 Script executed: #!/bin/bash
# Check what CSS classes the color-picker actually uses
rg 't-color-picker__panel' packages/ --type ts --type vueRepository: opentiny/tiny-vue Length of output: 88 🏁 Script executed: #!/bin/bash
# Check for tiny-color-picker__dropdown
rg 'tiny-color-picker__dropdown' packages/ --type ts --type vueRepository: opentiny/tiny-vue Length of output: 88 🏁 Script executed: #!/bin/bash
# Also search more broadly for color-picker panel classes
rg 'color-picker.*panel|__panel' packages/vue/src/color-picker/ -t ts -t vueRepository: opentiny/tiny-vue Length of output: 88 🏁 Script executed: #!/bin/bash
# Search for color-picker panel class definitions in source files
rg 'color-picker.*panel' packages/vue/src/color-picker/ -A 2 -B 2Repository: opentiny/tiny-vue Length of output: 43 🏁 Script executed: #!/bin/bash
# Look for all CSS classes in the color-picker component files
find packages/vue/src/color-picker -type f \( -name "*.ts" -o -name "*.vue" \) | xargs grep -h "class=" | head -20Repository: opentiny/tiny-vue Length of output: 218 🏁 Script executed: #!/bin/bash
# Check the placement.vue demo file to see what it actually contains
cat examples/sites/demos/pc/app/color-picker/placement.vue 2>/dev/null || echo "File not found"Repository: opentiny/tiny-vue Length of output: 444 🏁 Script executed: #!/bin/bash
# Look for any reference to placement-related elements
rg '#placement' examples/sites/demos/pc/app/color-picker/Repository: opentiny/tiny-vue Length of output: 295 Test is missing page navigation and uses incorrect selectors—it will fail immediately.
Add 🤖 Prompt for AI Agents |
||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <template> | ||
| <div> | ||
| <tiny-color-picker v-model="color" placement="top" /> | ||
| <tiny-color-picker v-model="color"/> | ||
| </div> | ||
| </template> | ||
|
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for placement-related files in the color-picker demo directory
fd 'placement' examples/sites/demos/pc/app/color-picker/Repository: opentiny/tiny-vue Length of output: 174 🏁 Script executed: # Find the placement test file
fd 'placement.spec' examples/Repository: opentiny/tiny-vue Length of output: 288 🏁 Script executed: # Check the structure of the color-picker demo directory
ls -la examples/sites/demos/pc/app/color-picker/ 2>/dev/null | head -20Repository: opentiny/tiny-vue Length of output: 1408 🏁 Script executed: # Read the placement test file to see what it expects
cat -n examples/sites/demos/pc/app/color-picker/placement.spec.tsRepository: opentiny/tiny-vue Length of output: 591 🏁 Script executed: # Read the placement demo file
cat -n examples/sites/demos/pc/app/color-picker/placement.vueRepository: opentiny/tiny-vue Length of output: 633 Demo is missing required The test Add a 🤖 Prompt for AI Agents |
||
|
|
||
| <script> | ||
| import { TinyColorPicker } from '@opentiny/vue' | ||
|
|
||
| export default { | ||
| components: { | ||
| TinyColorPicker | ||
| }, | ||
| data() { | ||
| return { | ||
| color: '#66ccff' | ||
| } | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .demo-margin { | ||
| margin: 8px 0; | ||
| } | ||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,11 +63,17 @@ export const renderless = (props, ctx: ISharedRenderlessParamHooks, { emit }: IS | |
| ) | ||
| const changeVisible = toggleVisible(isShow) | ||
| const { onConfirm, onCancel } = useEvent(state, emit, changeVisible, color) | ||
|
|
||
| // 根据 placement 决定动画方向 | ||
| const transitionName = () => { | ||
| return props.placement === 'top' ? 'tiny-zoom-in-bottom' : 'tiny-zoom-in-top' | ||
| } | ||
| const api = { | ||
| state, | ||
| changeVisible, | ||
| onConfirm, | ||
| onCancel | ||
| onCancel, | ||
| transitionName | ||
|
Comment on lines
+68
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== color-picker renderless module =="
sed -n '1,120p' packages/renderless/src/color-picker/vue.ts
echo
echo "== color-picker component wiring =="
sed -n '1,220p' packages/vue/src/color-picker/src/pc.vue
echo
echo "== usages of transitionName in the color-picker surface =="
rg -n -C2 '\btransitionName\b' \
packages/renderless/src/color-picker/vue.ts \
packages/vue/src/color-picker/src/pc.vue \
packages/vue/src/color-picker/src/index.tsRepository: opentiny/tiny-vue Length of output: 5557 🏁 Script executed: # Search for other renderless modules to understand the api array pattern
fd -t f 'vue\.ts$' packages/renderless/src --exec head -20 {} \; 2>/dev/null | head -100
# Look for setup function usage patterns across renderless modules
rg -A5 'setup\(\{.*renderless.*api' packages/vue/src --type vue --max-count 5Repository: opentiny/tiny-vue Length of output: 2814 🏁 Script executed: # Check if there are other renderless modules with api arrays and returned methods
rg 'export const api = \[' packages/renderless/srcRepository: opentiny/tiny-vue Length of output: 19504 🏁 Script executed: # Look for how setup function is defined or documented
fd -t f '(setup|common)' packages/ -name '*.ts' -name '*.vue' | head -20Repository: opentiny/tiny-vue Length of output: 291 🏁 Script executed: # Find the setup function implementation
fd -type f -name '*.ts' -o -name '*.js' packages/vue-common | head -20Repository: opentiny/tiny-vue Length of output: 231 🏁 Script executed: # Search for setup function definition
rg -l 'export.*setup' packages/vue-common --type ts --type js 2>/dev/null | head -5Repository: opentiny/tiny-vue Length of output: 93 🏁 Script executed: # Look in the common package
find packages -type d -name '*common*' 2>/dev/nullRepository: opentiny/tiny-vue Length of output: 211 🏁 Script executed: # Find setup function definition in vue-common
rg -n 'export.*setup' packages/vue-common/src --max-count 10Repository: opentiny/tiny-vue Length of output: 395 🏁 Script executed: # Read the vue-common index to see what's exported
cat packages/vue-common/src/index.tsRepository: opentiny/tiny-vue Length of output: 14503 Add
Suggested fix-export const api = ['state', 'changeVisible', 'onConfirm', 'onCancel', 'onHueUpdate', 'onSVUpdate', 'onColorUpdate']
+export const api = [
+ 'state',
+ 'changeVisible',
+ 'onConfirm',
+ 'onCancel',
+ 'onHueUpdate',
+ 'onSVUpdate',
+ 'onColorUpdate',
+ 'transitionName'
+]🤖 Prompt for AI Agents |
||
| } | ||
| return api | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,50 +1,53 @@ | ||||||
| <template> | ||||||
| <div | ||||||
| :class="[ | ||||||
| { | ||||||
| 'tiny-color-picker': true | ||||||
| }, | ||||||
| { 'tiny-color-picker': true }, | ||||||
| state.size ? 'tiny-color-picker--' + state.size : '' | ||||||
| ]" | ||||||
| @click="() => changeVisible(!state.isShow)" | ||||||
| > | ||||||
| <div | ||||||
| class="tiny-color-picker__inner" | ||||||
| :style="{ | ||||||
| background: state.hex ?? '' | ||||||
| }" | ||||||
| :style="{ background: state.hex ?? '' }" | ||||||
| > | ||||||
| <IconChevronDown /> | ||||||
| </div> | ||||||
| <Transition name="tiny-zoom-in-top"> | ||||||
| <color-select | ||||||
| @confirm="onConfirm" | ||||||
| @cancel="onCancel" | ||||||
| v-model="state.hex" | ||||||
| :visible="state.isShow" | ||||||
| :alpha="alpha" | ||||||
| :predefine="state.predefineStack" | ||||||
| :history="state.stack" | ||||||
| :format="format" | ||||||
| :style="{ | ||||||
| 'min-width': '330px' | ||||||
| }" | ||||||
| :color-mode="$props.colorMode" | ||||||
| :enable-history="state.enableHistory" | ||||||
| :enable-predefine-color="state.enablePredefineColor" | ||||||
| /> | ||||||
|
|
||||||
| <!-- 根据 placement 设置弹出位置 --> | ||||||
| <Transition :name="transitionName"> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's look at the specific file and context around line 17
head -30 packages/vue/src/color-picker/src/pc.vueRepository: opentiny/tiny-vue Length of output: 865 🏁 Script executed: # Find the renderless color-picker implementation
find . -path "*/renderless/src/color-picker*" -name "*.ts" | head -5Repository: opentiny/tiny-vue Length of output: 267 🏁 Script executed: # Search for transitionName definition in renderless
rg -n "transitionName\s*=" packages/renderless/src/ -B2 -A2Repository: opentiny/tiny-vue Length of output: 447 🏁 Script executed: # Check what `@opentiny/vue-common` setup returns
rg -n "export.*setup|return.*{" packages/vue-common/src/ -A3 -B1 | head -50Repository: opentiny/tiny-vue Length of output: 170 🏁 Script executed: # See how other color-picker related files use Transition
rg -n "Transition.*:name" packages/vue/src/color-picker/ -B1 -A1Repository: opentiny/tiny-vue Length of output: 276 🏁 Script executed: # Let's look at the full renderless setup function to see how transitionName is returned
cat -n packages/renderless/src/color-picker/vue.ts | sed -n '1,120p'Repository: opentiny/tiny-vue Length of output: 2968 🏁 Script executed: # Check the full pc.vue file to see the setup integration
cat -n packages/vue/src/color-picker/src/pc.vueRepository: opentiny/tiny-vue Length of output: 2919 🏁 Script executed: # Check how `@opentiny/vue-common` handles setup
rg -n "setup\s*\(" packages/vue-common/src/ -A 10 | head -80Repository: opentiny/tiny-vue Length of output: 1241 🏁 Script executed: # Let's check if there are any computed or unwrap mechanisms for functions in the renderless
rg -n "computed\|unref\|isRef" packages/renderless/src/color-picker/vue.tsRepository: opentiny/tiny-vue Length of output: 43 🏁 Script executed: # Let's look at the `@opentiny/vue-common` setup function implementation
find . -path "*/vue-common/src*" -name "*.ts" -o -name "*.js" | grep -v node_modules | head -10Repository: opentiny/tiny-vue Length of output: 431 🏁 Script executed: # Search for the setup function that's imported in pc.vue
rg -n "export.*setup\|function setup" packages/vue-common/src/ -B2 -A15 | head -100Repository: opentiny/tiny-vue Length of output: 43 🏁 Script executed: # Let's check if there's any special handling in how renderless properties are exposed
rg -n "transitionName\|computed" packages/vue-common/src/ -B2 -A2 | head -80Repository: opentiny/tiny-vue Length of output: 43 🏁 Script executed: # Let's test by looking at how similar components handle functions from renderless
rg -n "Transition.*:name" packages/vue/src/ -l | head -5Repository: opentiny/tiny-vue Length of output: 101 🏁 Script executed: # Check the actual vue-common setup function more carefully
cat -n packages/vue-common/src/index.ts | head -100Repository: opentiny/tiny-vue Length of output: 3655 🏁 Script executed: # Continue reading the setup function
cat -n packages/vue-common/src/index.ts | sed -n '100,200p'Repository: opentiny/tiny-vue Length of output: 3713 🏁 Script executed: # Let's look for the setup function specifically
rg -n "^export.*setup|^const setup|^function setup" packages/vue-common/src/index.ts -A 30Repository: opentiny/tiny-vue Length of output: 3122 🏁 Script executed: # Let's search in all files within vue-common
find packages/vue-common/src -name "*.ts" -exec grep -l "export.*setup" {} \;Repository: opentiny/tiny-vue Length of output: 93 🏁 Script executed: # Let's check if there's a setup function that wraps renderless
rg -rn "export.*setup\s*=" packages/vue-common/src/ -A 20 | head -100Repository: opentiny/tiny-vue Length of output: 2855
In the renderless layer, Either invoke it in the template or convert it to a computed property in the renderless layer. Option A: Invoke in template- <Transition :name="transitionName">
+ <Transition :name="transitionName()">Option B: Convert to computed in renderless (preferred)In - const transitionName = () => {
- return props.placement === 'top' ? 'tiny-zoom-in-bottom' : 'tiny-zoom-in-top'
- }
+ const transitionName = ctx.computed(() => {
+ return props.placement === 'top' ? 'tiny-zoom-in-bottom' : 'tiny-zoom-in-top'
+ })📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| <div | ||||||
| class="tiny-color-picker__dropdown" | ||||||
| :class="`tiny-color-picker__dropdown--${placement}`" | ||||||
| v-show="state.isShow" | ||||||
| > | ||||||
| <color-select | ||||||
| @confirm="onConfirm" | ||||||
| @cancel="onCancel" | ||||||
| v-model="state.hex" | ||||||
| :visible="state.isShow" | ||||||
| :alpha="alpha" | ||||||
| :predefine="state.predefineStack" | ||||||
| :history="state.stack" | ||||||
| :format="format" | ||||||
| :style="{ 'min-width': '330px' }" | ||||||
| :color-mode="$props.colorMode" | ||||||
| :enable-history="state.enableHistory" | ||||||
| :enable-predefine-color="state.enablePredefineColor" | ||||||
| /> | ||||||
| </div> | ||||||
| </Transition> | ||||||
| </div> | ||||||
| </template> | ||||||
|
|
||||||
| <script> | ||||||
| import { renderless, api } from '@opentiny/vue-renderless/color-picker/vue' | ||||||
| import { props, setup, defineComponent } from '@opentiny/vue-common' | ||||||
| import { IconChevronDown } from '@opentiny/vue-icon' | ||||||
| import colorSelect from '@opentiny/vue-color-select-panel' | ||||||
| import '@opentiny/vue-theme/color-picker/index.less' | ||||||
|
|
||||||
| export default defineComponent({ | ||||||
| name: 'TinyColorPicker', | ||||||
| emits: ['update:modelValue', 'confirm', 'cancel'], | ||||||
| props: [ | ||||||
| ...props, | ||||||
|
|
@@ -57,14 +60,17 @@ export default defineComponent({ | |||||
| 'format', | ||||||
| 'enableHistory', | ||||||
| 'enablePredefineColor', | ||||||
| 'colorMode' | ||||||
| 'colorMode', | ||||||
| 'placement' | ||||||
| ], | ||||||
| components: { | ||||||
| IconChevronDown: IconChevronDown(), | ||||||
| ColorSelect: colorSelect | ||||||
| }, | ||||||
| setup(props, context) { | ||||||
| return setup({ props, context, renderless, api }) | ||||||
| const state = setup({ props, context, renderless, api }) | ||||||
| return { ...state } | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||
| } | ||||||
| }) | ||||||
| </script> | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.