Comments (12)
Use case 1:
I'm looking at chess.com and they record the piece that was clicked and allow you to move the piece by clicking the target square. This is a very nice feature(I use it all of the time on my ipad playing on chess.com)and wasn't implemented in chessboard.js but I definitely want it for Chessboard.jsx.
I would then need to use hover for styling the desired target
So have some sort of unique hover styling over a desired target. This seems like a useful feature
Use case 2:
While developing a play board, I want to prevent the user from dragging a piece that is not allowed to be moved
Ok, so as of now draggable prop is for the entire board, that is not going to work for your use case.
from chessboardjsx.
@willb335 Yes, I expect that draggable
would apply to the whole board... this is a good thing and I need it too :)
Here though, I need to make the decision on a piece-by-piece basis at the moment dragging begins on a piece. Some pieces are valid to drag (white's move) and some pieces have valid moves (king has no adjacent empty squares) and so I want to prevent the drag operation from even starting.
from chessboardjsx.
Ok, got it. I'll use your suggested signature. Not sure when I'll start on this. I have some time this coming weekend
from chessboardjsx.
perhaps draggable
prop could take a boolean for the whole board or an object for specific squares. draggable={ {'e5': false } }
.
from chessboardjsx.
@csharptest
a1ee12f
I provided the onClick feature and updated Demo.js. Take a look at 'With Move Validation.'
from chessboardjsx.
I was looking for this feature for use case 2.
I can't find the Demo.js being referred to here. Neither the src/Demo.js in this repository nor the one at https://codesandbox.io/s/lp32ojqzqm?from-embed seems to have anything relevant.
Does it provide a way to reject picking up the piece? I'm thinking the handler should return true if the piece is allowed to be picked up and false if not.
from chessboardjsx.
@furrykef
After looking at this again I realized I misunderstood use case 2 from @csharptest.
see #28
I used: Signature: function( { piece: string, sourceSquare: string } ) => bool
Please check out Demo.js again with the 'Conditionally Disable Drag' demo
Please let me know if this is a solution for you
from chessboardjsx.
As I said before, I don't know where the Demo.js you refer to is.
from chessboardjsx.
Ok, if you fetch the allow-drag
branch I committed in #28 and then run npm run start
that will load the Demo.js component(usually called App.js, it's the root component)
If you want to see the implementation code for allowDrag
then go to https://github.com/willb335/chessboardjsx/blob/allow-drag/src/integrations/AllowDrag.js
from chessboardjsx.
That looks fine to me. Thanks.
One quibble: I notice the mouse cursor changes to a hand icon when you mouseover a piece, whether that piece is draggable or not. I don't think it should do that when you mouseover a non-draggable piece. It's not remotely an urgent matter for me, though.
from chessboardjsx.
Ok, I'll look into fixing that
from chessboardjsx.
cursor: 'not-allowed'
implemented for non-draggable pieces and will be available for 2.0.1
from chessboardjsx.
Related Issues (20)
- why allowDrag is not called at the time of "onStartDrag", but always for all squares? HOT 1
- Legacy context API warnings in React 16.3+
- calcWidth , the zoom feature and the yellow highlight HOT 3
- Wired 1st move after FEN changed HOT 1
- context API warnings in React HOT 3
- WebpackError: ReferenceError: window is not defined when using ChessboardJSX with Gatsby HOT 1
- Next js support? HOT 7
- How to achieve square styles in the landing page demo? HOT 3
- using calcwidth HOT 6
- Ability to select and move rather drag and drop HOT 1
- Chessboard does not always render position updates HOT 4
- Can't drag&drop after dynamically change position HOT 3
- Rotate board - orientation left right HOT 1
- adding sound effect HOT 2
- Not filled Rook / Queen HOT 2
- React Warning HOT 1
- Ability to create promotion panel.
- Adding onStartDrag callback HOT 2
- Piece discoloration after rook/queen capture
- how can I integrate this with stockfish 16?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chessboardjsx.