-
Notifications
You must be signed in to change notification settings - Fork 323
feat(drawer): [drawer]add props of height #2184
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
Conversation
WalkthroughThe changes introduce a new Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (14)
examples/sites/demos/pc/app/drawer/placement-composition-api.vue (3)
8-15
: LGTM! Consider adding an aria-label for accessibility.The implementation of the drawer for 'left' and 'right' placements looks good. The conditional rendering and prop bindings are correct.
Consider adding an
aria-label
to improve accessibility:<tiny-drawer v-if="placement === 'left' || placement === 'right'" title="标题" :placement="placement" v-model:visible="visible" + :aria-label="`${placement} drawer`" > <div style="padding: 32px">left或者right内容区域</div> </tiny-drawer>
17-24
: LGTM! Consider making the height dynamic and adding an aria-label.The implementation of the drawer for 'top' and 'bottom' placements looks good. The conditional rendering and prop bindings are correct.
Consider the following improvements:
- Make the height prop dynamic to allow for more flexibility:
- height="400px" + :height="drawerHeight"Then add a
drawerHeight
ref in the<script setup>
section:const drawerHeight = ref('400px')
- Add an
aria-label
to improve accessibility:<tiny-drawer v-if="placement === 'top' || placement === 'bottom'" title="标题" :placement="placement" v-model:visible="visible" :height="drawerHeight" + :aria-label="`${placement} drawer`" > <div style="padding: 32px">top或者bottom区域</div> </tiny-drawer>
These changes will make the component more flexible and accessible.
Issues Found
The review highlights several valid concerns regarding the
placement-composition-api.vue
component:
Missing Tests:
- No test files are associated with
placement-composition-api.vue
. It's essential to add comprehensive tests to ensure the new functionality works as intended.Height Prop for Left/Right Placements:
- The
height
prop is currently only applied to top/bottom placements. Consider extending theheight
prop to left/right placements for consistency and enhanced functionality.Documentation Updates:
- Documentation does not mention the
height
prop for the drawer component. Update the relevant documentation to reflect this addition and provide clear guidance on its usage.To address these issues, please take the following actions:
Add Tests:
- Create unit tests for
placement-composition-api.vue
to cover various placement scenarios and ensure theheight
prop functions correctly.Extend Height Prop Usage:
- Modify the component to include the
height
prop for left/right placements, ensuring consistent behavior across all placements.Update Documentation:
- Enhance the component's documentation to include explanations and examples of the
height
prop usage for left/right placements.🔗 Analysis chain
Line range hint
1-41
: Overall structure is good, but consider adding documentation and tests.The implementation demonstrates the drawer component with different placements effectively. However, there are a few points to consider:
- Add comments or documentation to explain the component's purpose and usage.
- The PR objectives mentioned adding a height prop, which is implemented for top/bottom placements. Consider if it should also be applicable for left/right placements.
- As noted in the PR objectives, tests and documentation updates are missing. These should be added to ensure the new functionality is properly tested and documented.
To address these points:
- Add a comment at the top of the file explaining the component's purpose and usage.
- If applicable, add a height prop to the left/right drawer as well.
- Create unit tests for the new functionality.
- Update the component's documentation to reflect the new height prop.
To check for existing tests and documentation, run:
Verification Successful:
computedHeight
Function Implemented CorrectlyThe
computedHeight
function has been successfully located and implemented as expected. The addition aligns with the PR objectives and maintains consistency within the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of computedHeight function # Test: Search for the computedHeight function implementation rg --type typescript -A 10 'export const computedHeight'Length of output: 279
Script:
#!/bin/bash # Description: Search for the computedHeight function implementation in TypeScript files without using --type flag # Find all .ts and .tsx files and search for 'export const computedHeight' fd --extension ts --extension tsx --exec rg -A 10 'export const computedHeight' {}Length of output: 345
packages/renderless/src/drawer/index.ts (2)
20-32
: LGTM with suggestions for improvementThe
computedHeight
function is well-implemented and consistent with the existingcomputedWidth
function. However, consider the following suggestions to improve robustness and type safety:
- Add support for different units (e.g., percentages, em) in the height property.
- Implement validation to ensure the height is a positive number.
- Instead of using type assertion
as IDrawerCT
, consider updating the type definition ofconstants
to avoid potential type issues.Here's a potential refactoring that addresses these points:
import { isNumber } from '../common/deps/utils' // Assume this utility function exists export const computedHeight = ({ state, designConfig, props, constants }: Pick<IDrawerRenderlessParams, 'state' | 'designConfig' | 'props' | 'constants'>) => (): string => { if (state.height) { return isNumber(state.height) ? `${state.height}px` : state.height } const height = props.height || designConfig?.constants?.DEFAULT_HEIGHT || constants.DEFAULT_HEIGHT if (isNumber(height)) { return height > 0 ? `${height}px` : '0px' } return height || '0px' }This refactored version:
- Supports different units by checking if the height is a number before appending 'px'.
- Ensures the height is non-negative when it's a number.
- Removes the need for type assertion by assuming
constants.DEFAULT_HEIGHT
is correctly typed.To ensure that the
IDrawerCT
interface includes theDEFAULT_HEIGHT
property, run the following script:#!/bin/bash # Description: Verify the IDrawerCT interface includes DEFAULT_HEIGHT # Test: Search for the IDrawerCT interface definition rg --type typescript 'interface IDrawerCT' -A 10This will help us confirm that the
DEFAULT_HEIGHT
property is properly defined in theIDrawerCT
interface, potentially eliminating the need for the type assertion.
20-32
: Verify integration and update documentation for the new height propertyThe addition of the
computedHeight
function is a good enhancement to the drawer component. To ensure proper integration and maintainability, please address the following points:
- Update the drawer component to use this new
computedHeight
function.- Add documentation for the new height property, including its usage and any constraints.
- Update existing tests and add new ones to cover the height functionality.
To help verify the integration, run the following script to check for updates in related files:
This script will help us verify that the necessary updates have been made across the codebase to support the new height property.
examples/sites/demos/apis/drawer.js (1)
Line range hint
1-186
: Summary: New 'height' property added to drawer component APIThe changes in this file are limited to the addition of the 'height' property for the drawer component. This new property enhances the component's flexibility by allowing users to set a custom height for the drawer, particularly useful for top and bottom placements in PC mode.
Key points:
- The new property is well-documented and consistent with existing properties.
- It's correctly limited to 'pc' mode.
- The stability version is properly noted.
Overall, this is a valuable addition to the drawer component that shouldn't introduce any breaking changes to existing implementations.
To ensure a smooth integration of this new feature, please:
- Verify the drawer component's internal logic handles the new 'height' property correctly.
- Update the 'placement' demo for PC to showcase the usage of the 'height' property.
- Consider adding validation for the 'height' property value in the component's props definition.
@@ -19,6 +19,7 @@ export const defaultConfigs = { | |||
customClass: null, | |||
placement: 'right', | |||
width: null, | |||
height: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Add Documentation and Tests for the height
Property
The height
property has been added to the drawer service implementation. However, there are no corresponding documentation files or test specifications found in the repository.
Please address the following to ensure complete implementation:
- Documentation: Create or update Markdown files related to the drawer component to include details about the new
height
property. - Tests: Add test cases in the existing test suite to validate the functionality of the
height
property.
🔗 Analysis chain
LGTM! Consider additional steps for full implementation.
The addition of the height
property to defaultConfigs
is consistent with the existing code structure and aligns with the PR objective. Good job on maintaining code consistency.
To ensure full implementation, please verify the following:
-
Check if the
height
property is properly handled in the drawer component file: -
Update the component's documentation to reflect this new property:
-
Add or update tests for the new
height
property:
Would you like assistance in updating the documentation or creating test cases for the new height
property?
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for usage of the new height property in the drawer component
rg --type typescript 'height.*props' packages/vue/src/drawer
Length of output: 97
Script:
#!/bin/bash
# Search for existing documentation files related to the drawer component
fd -e md drawer packages/vue/src/drawer
Length of output: 41
Script:
#!/bin/bash
# Search for existing test files related to the drawer component
fd -e spec.ts drawer packages/vue/src/drawer
Length of output: 46
Script:
#!/bin/bash
# Corrected search for usage of the new height property in the drawer component
rg --type ts 'height\s*:' packages/vue/src/drawer
Length of output: 155
Script:
#!/bin/bash
# Verify if any Markdown documentation files exist for the drawer component
fd --extension md drawer packages/vue/src/drawer
Length of output: 50
Script:
#!/bin/bash
# Verify if any test specification files exist for the drawer component
fd --extension spec.ts drawer packages/vue/src/drawer
Length of output: 55
@@ -31,7 +31,7 @@ | |||
]" | |||
:style="{ | |||
width: ['left', 'right'].includes(placement) ? state.computedWidth : null, | |||
height: ['top', 'bottom'].includes(placement) && dragable && state.height ? state.height + 'px' : null, | |||
height: ['top', 'bottom'].includes(placement) || dragable ? state.computedHeight : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Potential Issue: computedHeight
may be undefined
The computedHeight
state property is used in the height binding but does not appear to be defined or assigned anywhere in the codebase. This could lead to unexpected behavior or runtime errors.
- Action Required:
- Define
computedHeight
appropriately within the component's state or computed properties. - If
computedHeight
is unnecessary, consider removing its usage from the height binding.
- Define
🔗 Analysis chain
Approve with suggestions: Height style binding modification
The change increases the flexibility of the drawer component by allowing the height to be set in more scenarios. This is a good improvement.
However, I have a concern:
- The removal of the
state.height
check might lead to unexpected behavior ifstate.computedHeight
is not properly managed.
To ensure the change doesn't introduce any issues, please verify:
- The management of
state.computedHeight
in all scenarios where it's used. - The impact of this change on the drawer's behavior when
dragable
is true but no explicit height is set.
You can use the following script to investigate the usage of computedHeight
:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for computedHeight usage in the codebase
rg 'computedHeight' --type vue
Length of output: 58
Script:
#!/bin/bash
# Search for computedHeight usage in .vue files using glob pattern
rg 'computedHeight' --glob '*.vue'
Length of output: 168
Script:
#!/bin/bash
# Search for definitions or assignments of computedHeight in .vue files
rg 'computedHeight\s*[:=]' --glob '*.vue'
Length of output: 177
{ | ||
name: 'height', | ||
type: 'string', | ||
defaultValue: "'500px'", | ||
desc: { | ||
'zh-CN': '设置抽屉的高度', | ||
'en-US': 'Set the height of the drawer' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'placement', | ||
mfDemo: '', | ||
meta: { | ||
stable: '3.19.0' | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Drawer component includes the new 'height' property, but demos need updates to showcase it.
- The
'height'
property is correctly implemented in the drawer component's type definitions. - However, the demo files (
examples/sites/demos/apis/drawer.js
andexamples/sites/demos/mobile-first/app/drawer/webdoc/drawer.js
) do not utilize the'height'
property. - Please update the relevant demo files to include examples demonstrating the usage of the new
'height'
property, ensuring that it is properly showcased in different placements (e.g., top and bottom).
🔗 Analysis chain
Verify implementation and update demo for the new 'height' property.
While the addition of the 'height' property is well-documented here, it's important to ensure that:
- The drawer component's internal logic correctly applies this new property.
- The 'placement' demo for PC is updated to showcase the usage of the new 'height' property, especially for top and bottom placements.
To verify the implementation, please run the following script:
Please review the results of this script and make any necessary updates to the component implementation and demos.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the implementation of the new 'height' property in the drawer component
# Test 1: Check if the drawer component file includes logic for the 'height' property
echo "Checking drawer component file for 'height' property implementation:"
rg --type vue 'props.*height' src/drawer
# Test 2: Check if the 'placement' demo file has been updated to include the 'height' property
echo "Checking 'placement' demo file for 'height' property usage:"
rg --type vue 'height=' examples/sites/demos/pc/drawer/placement.vue
# Test 3: Check for any potential regressions in other demos
echo "Checking other drawer demos for potential regressions:"
rg --type vue ':height' examples/sites/demos/pc/drawer
Length of output: 663
Script:
#!/bin/bash
# Description: Verify the implementation of the new 'height' property in the drawer component
# Test 1: Check if the drawer component file includes logic for the 'height' property
echo "Checking drawer component file for 'height' property implementation:"
rg 'props.*height' src/drawer.vue --glob '*.vue'
# Test 2: Check if the 'placement' demo file has been updated to include the 'height' property
echo "Checking 'placement' demo file for 'height' property usage:"
rg 'height=' examples/sites/demos/pc/drawer/placement.vue --glob '*.vue'
# Test 3: Check for any potential regressions in other demos
echo "Checking other drawer demos for potential regressions:"
rg ':height' examples/sites/demos/pc/drawer/*.vue --glob '*.vue'
Length of output: 820
Script:
#!/bin/bash
# Description: Locate the drawer component and its demo files in the repository
# Search for files related to 'drawer'
echo "Searching for files related to 'drawer' in the repository:"
fd 'drawer' --type f
Length of output: 633
Script:
#!/bin/bash
# Description: Locate the drawer component implementation and verify the 'height' property
# Search for the 'height' property in TypeScript files within the renderless package
echo "Searching for 'height' property in TypeScript files within 'packages/renderless':"
rg 'height' packages/renderless/**/*.ts --glob '*.ts'
# Verify if the 'height' property is used in the identified demo files
echo "Verifying 'height' property usage in demo files:"
rg 'height=' examples/sites/demos/apis/drawer.js
rg 'height=' examples/sites/demos/mobile-first/app/drawer/webdoc/drawer.js
Length of output: 11294
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
height
property for the drawer component, allowing users to customize the drawer's height.tiny-drawer
component based on its placement, improving layout flexibility.computedHeight
for dynamic height calculation based on user-defined settings.Bug Fixes
Chores